Get list of products by ids

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Oleh
Posts: 14
Joined: 13 Jul 2020, 08:11

Get list of products by ids

Post by Oleh » 13 Jul 2020, 08:18

Hi,
I use "aimeos/aimeos-laravel": "~2020.07"
I can get product by id using this url: http://localhost/jsonapi/product?id=4

But I want to get several products with id 1,2,3,4
I try to build url like: id=1,2,3,4 or id=1&id=2&id=3 or id[1]=1&id[2]&id=[3]

But it didn't work.
Whether jsonapi provides such a possibility, because I did not find any information about it in the documentation

User avatar
aimeos
Administrator
Posts: 8636
Joined: 01 Jan 1970, 00:00

Re: Get list of products by ids

Post by aimeos » 14 Jul 2020, 10:25

Use the "filter" parameter and add:

Code: Select all

filter[||][][product.id]=1&filter[||][][product.id]=2&...
https://aimeos.org/docs/Developers/Clie ... the_result
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Oleh
Posts: 14
Joined: 13 Jul 2020, 08:11

Re: Get list of products by ids

Post by Oleh » 14 Jul 2020, 10:34

Thank you for reply, but I got an error
"errors": [
{
"title": "Invalid operator \"product.id\""
}
]

This is my url: http://localhost/jsonapi/product?filter[||][][product.id]=1&filter[||][][product.id]=2

User avatar
aimeos
Administrator
Posts: 8636
Joined: 01 Jan 1970, 00:00

Re: Get list of products by ids

Post by aimeos » 14 Jul 2020, 10:44

Sorry, it must be:

Code: Select all

filter[||][][==][product.id]=1&filter[||][][==][product.id]=2&...
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Oleh
Posts: 14
Joined: 13 Jul 2020, 08:11

Re: Get list of products by ids

Post by Oleh » 14 Jul 2020, 11:06

Thank you, unfortunately I tried this and got error:

"errors": [
{
"title": "Invalid operator \"0\""
}
]

My url: http://localhost/jsonapi/product?filter[||][][==][product.id]=1&filter[||][][==][product.id]=2

User avatar
aimeos
Administrator
Posts: 8636
Joined: 01 Jan 1970, 00:00

Re: Get list of products by ids

Post by aimeos » 14 Jul 2020, 11:24

Please keep in mind that "=" is a special character in URLs and you have to escape those chars. The correctly escaped URL is:

Code: Select all

/jsonapi/product?filter%5B%7C%7C%5D%5B0%5D%5B%3D%3D%5D%5Bproduct.id%5D=1
which is the same as above but correctly escaped.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Oleh
Posts: 14
Joined: 13 Jul 2020, 08:11

Re: Get list of products by ids

Post by Oleh » 14 Jul 2020, 12:22

Thank you

Post Reply