3

Trying to find a way how to integrate Magento 2 via cURL to search for a customer.

For Example the below command is able to bring the customer details of 8

curl -X GET "http://example.com/index.php/rest/V1/customers/8" 
     -H "Authorization: Bearer myaccesstoken"

In the similar fashion how can I construct the search URL with Search Criteria

I spent a day with this website and no luck.

curl -X GET http://example.com/index.php/rest/V1/customers/search 
     -H "Authorization: Bearer xxxxxxx" 
     -d '{"searchCriteria":{"filterGroups":[{"filters":[{"field":"email","value":"abcd@gmail.com","condition_type":"eq"}]}]}}'

And I got the error

{"message":"%fieldName is a required field.","parameters":{"fieldName":"searchCriteria"}}

There is something wrong in my request...

  • cyrillschumacher.com/2015/01/02/… – B00MER Jan 19 '16 at 14:37
  • @B00MER i spent a day with the website and no luck... Update my question with few code snippet now. – Malaiselvan Jan 19 '16 at 14:43
  • Sorry didn't realize you had already posted this link in your question, added an answer. – B00MER Jan 19 '16 at 15:27
7

Finally after 3 days of struggle got the answer how to put the search criteria in cURL

curl -X GET "http://example.com/index.php/rest/V1/customers/search
    ?searchCriteria[filterGroups][0][filters][0][field]=email
    &searchCriteria[filterGroups][0][filters][0][value]=abc@gmail.com
    &searchCriteria[filterGroups][0][filters][0][condition_type]=eq" 
    -H "Authorization: Bearer xxxxxx" 
    -H "Content-type: application/json" -g 

The above command will just connect to my store and search for the customer who is having the exact email address.

0

Try a JSON Request like so:

{"url":"/V1/customerAccounts/Search","verb":"PUT","req":{"searchCriteria":{"filterGroups":[{"filters":[{"field":"email","condition_type":"like","value":"%test%"},{"field":"updated_at","condition_type":"gt","value":"2014-04-20"}]}],"current_page":1,"page_size":20}}}

...and for further reference:

  • @BOOMER Sorry, i dont have any clue how to use this JSON along with the curl. The magento document says GET, but the example shows PUT... Is it possible to put a full URL like the one I asked in my question. – Malaiselvan Jan 19 '16 at 15:37
  • Updated to one liner – B00MER Jan 19 '16 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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