1

I've been trying a lot of things and can't seem to figure out what should be pretty simple... How can I make a request with curl in command line to /index.php/rest/V1/products so that I simply get the list of all products?

Everything I tried got me this error:

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

If I start from this, what should I add?

curl -H "Authorization: Bearer xxxxxxxxxxxxxxxxxxxx" "http://example.com/index.php/rest/V1/products"

Thank you!

0

This will be enough

curl -H "Authorization: Bearer xxxxxxxxxxxxxxxxxxxx" "http://example.com/index.php/rest/V1/products?searchCriteria"
1

We are using below code to get product list from third party API. But we are not doing it using command line, we have written curl code to get response. Hope this will also help you.

$curl     = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL            => "YOUR API URL",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING       => "",
CURLOPT_MAXREDIRS      => 10,
CURLOPT_TIMEOUT        => 50,
CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST  => "POST",
CURLOPT_POSTFIELDS     => "{\n\"user\":\"$username\",\n\"pwd\":\"$password\",\n\"DS\":\"$ds\"\n}",
CURLOPT_HTTPHEADER     => array(
        "cache-control: no-cache",
        "content-type: application/json",
        "postman-token: 26e3f35f-8c91-4c29-e690-ddbc42e62755"
    ),
));
$response = curl_exec($curl);
$err      = curl_error($curl);
curl_close($curl);
0

There we go:

curl -g -H "Authorization: Bearer xxxxxxxxxxxxxxxxxxxx" "http://example.com/index.php/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=name&searchCriteria[filter_groups][0][filters][0][value]=%25&searchCriteria[filter_groups][0][filters][0][condition_type]=like"

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.