Question

I'm trying to retrieve recent orders from Magento 2.3.5, via REST API. I use this command:

curl -X GET "https://my_magento_site/index.php/rest/V1/orders/search?searchCriteria[filter_groups][0][filters][0][field]=created_at&searchCriteria[filter_groups][0][filters][0][value]=2021-01-01&searchCriteria[filter_groups][0][filters][0][condition_type]=gt" -H "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "Content-type: application/json" -g -o C:\orders.json

What I get is this error in my orders.json:

{"message":"The \"search\" value's type is invalid. The \"int\" type was expected. Verify and try again."}

I'm pretty sure REST API is working fine and authentication is OK. If I simply replace "orders" with "customers" in the above command, I get all recently added customers. Also issuing:

curl -X GET "https://my_magento_site/index.php/rest/V1/orders/1" -H "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "Content-type: application/json" -g -o C:\orders.json

returns my order "1" details.

What may be the problem ?

Was it helpful?

Solution

I answer myself, hoping this can help someone else.

I investigated further and found that removing the "/search" part from the URI, solves the problem. This is the working curl command:

curl -X GET "https://my_magento_site/index.php/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=created_at&searchCriteria[filter_groups][0][filters][0][value]=2021-01-01&searchCriteria[filter_groups][0][filters][0][condition_type]=gt" -H "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "Content-type: application/json" -g -o C:\orders.json

Note the "/orders?searchCriteria" instead of "/orders/search?searchCriteria"

The strange thing is that, if I query customers, the "/search" is mandatory (without it I receive an error). So my experience is I have to use "/search" for customers and not for orders. Haven't tried other collections by now.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top