cancel
Showing results for 
Search instead for 
Did you mean: 

error when trying to load product with api

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

error when trying to load product with api

Hello Everyone,

I am developing an app to load products from csv files to magento, when trying to load products using the api I get the following error:

 

{"message":"Spanish translate","parameters":{"resources":"Magento_Catalog:Smiley Tongueroducts"}}

 

The eror is based on a connection with curl.

 

Can anyone know what the following error is? I had never appeared bef.

 

Thank you very much!
La madrilena.

3 REPLIES 3

Re: error when trying to load product with api

Hi @la_madrilena,

 

Can you share the code with the request?

Re: error when trying to load product with api

 

$token =  getToken($user, $password);

$products = getProductos();

$answer = loadProducto($products, $token);

 

function loadProducto($products, $token)
{

    $setHeaders = array('Content-Type:application/json','Authorization:Bearer'. $token);

    $requestURL = "http://localhost/tienda/index.php/rest/V1/products";

    foreach ($productos as $product) { 

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $requestURL);

        curl_setopt($ch,CURLOPT_POSTFIELDS, $product);

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_HTTPHEADER, $setHeaders);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

       

        if(curl_exec($ch)===false){
            echo "Curl error: " . curl_error($ch)."\n";
        }else{
            $response = curl_exec($ch) ?: "";
        }
        curl_close($ch);

        return $response;
}
}

 

This is my code, any help is welcome!.

Re: error when trying to load product with api

Hi @la_madrilena,

 

I guess the problem (or confussion base don the documentaiton) is that you wuill need (I guess) to add the searchCriteria param.

I've tested with:

 

http://www.domain.com/rest/V1/products?searchCriteria[page_size]=2

And I'm being able to get some data. Also, I've used the search criteria to request some specific SKU:

 

http://www.domain.com/rest/V1/products?searchCriteria[filterGroups][0][filters][0][field]=sku&searchCriteria[filterGroups][0][filters][0][condition_type]=eq&searchCriteria[filterGroups][0][filters][0][value]=your-sku