Page 1 of 1

How to create custom (detailed) queries with the API?

Posted: 22 Feb 2018, 20:03
by cecosd
Hello to everyone who reads this!
I have a specific issue/question or however you call it. :)

I have a VueJS front end where I make a portal for some of my customers to view their products/reviews/ yada yada...

I need to make a detailed queries for my products page.
Query needs to say:
Get all the products -> grab their attributes with texts -> grab the stock levels for each product -> images for each product -> and you get the idea...

I want to learn how to make such big API calls.

It will mean the world to me if someone helps me solfing this problem. And also I thing this will help people like me with such tasks.

Thanks in advance,
Tsvetan (Ted)

Re: How to create custom (detailed) queries with the API?

Posted: 23 Feb 2018, 00:19
by aimeos
This only requires two API calls in the latest version: One for the product and related data and one for the stock levels

To include the related product data in the response of the JSON REST API, you need to add the "included" parameter:
https://aimeos.org/docs/Developers/Clie ... _resources

In your case the value for "included" would be "attribute,media,price,product,text". In the latest 2018.01 version, you will also get the related data of the attributes, media, prices and texts as well. In 2017.10 and before, you will have to fetch them separately with another API call for each resource.

Re: How to create custom (detailed) queries with the API?

Posted: 25 Feb 2018, 19:48
by cecosd
Hey aimeos,
That was helpful! But here is a nex question.
It seem I can't get the stock levels for a product. I upgraded to 2018.01.

When I do the API call
jsonapi/stock?ai[filter][s_prodcode][==]=1
I can't get the stocklevel for all products.
I am missing something...
Thanks

Re: How to create custom (detailed) queries with the API?

Posted: 26 Feb 2018, 23:23
by aimeos
Your filter parameter is wrong and you need something like this:

jsonapi/stock?ai[filter][==][s_prodcode]=abcd

If you need the "ai" prefix depends on if it's listed in the (OPTIONS) response.

The documentation for filtering is here:
https://aimeos.org/docs/Developers/Clie ... the_result