0

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 ?

2
  • Did you check Magento core file where this error generated? Try to debug there, something may missing
    – Jack
    Feb 8, 2021 at 16:46
  • I've no access to filesystem. Magento is hosted by a third party. I only have an admin access to console. What should I check from there ? Can't see any special thing related to API, apart Integration token generation.
    – Massimo
    Feb 8, 2021 at 18:00

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.