cancel
Showing results for 
Search instead for 
Did you mean: 

REST API issue: created a product success but returned header 404

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

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

REST API issue: created a product success but returned header 404

Hi there

 

I wrote a test script of creating a new product into Magento by REST API, I referenced the official website: http://www.magentocommerce.com/api/rest/introduction.html#RESTAPIIntroduction-PreparingRESTAPIforthe...  

 

The core code is:

       $headers = array('Content-Type' => 'application/json');
       $oauthClient->fetch('http://remote.../api/rest/products', json_encode($arr), OAUTH_HTTP_METHOD_POST, $headers) ;

 

The program created a new product in Magento successfully but returned a 404 error. I checked the Exception message and found the script tried to read the product created:

 

+debugInfo: array:6 [
      "sbs" => "POST&http%3A%2F%2Fbnzl.magento%2Fapi%2Frest%2Fproducts%2F33&oauth_consumer_key%3D5615fe6e7db7665571d51c9818757105%26oauth_nonce%3D1619355d2b0b6f08e40.07852739%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1439871158%26oauth_token%3D78f612cb71c504b2154001b61e964caa%26oauth_version%3D1.0"
      "headers_sent" => """
        POST /api/rest/products/33 HTTP/1.1

 

I know the error caused by reading a product should use "POST" not "GET", but I don't know why the script executes reading the product after being created. Any hero could help me?

1 REPLY 1

Re: REST API issue: created a product success but returned header 404

Hi, there

 

I found the reason of this error. After creating a new product with REST API, my program(Callback script) returns a redirect request: "HTTP Header CODE 302,  Location: .../api/rest/customers/:id", but the function "$oauthClient->fetch()" in the program can not execute this request correctly, it seems that it would try to retrieve the target with "POST" not "GET", so it can't get data.

 

I don't know what reason it is caused, I only could disable redirect in oauth ", analyze and get the new product id  from dreceived header as  a temporary solution.

$oauthClient->disableRedirects();

 

Hope it's useful for encountering same problem with me, if anybody who knows the reason please share with us, thank you very much.