double-break / spapi-php

Amazon Selling Partner API PHP Client
MIT License
56 stars 48 forks source link

Help Needed on CURL error!! #51

Closed jsanthoshaws closed 2 years ago

jsanthoshaws commented 2 years ago

PHP Fatal error: Uncaught GuzzleHttp\Exception\RequestException: cURL error 3: (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) in /home/austinba/apps.santhoshkumarj.com/RenewedInventory/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:209 Stack trace:

Code FYR : // content type of the feed data to be uploaded.

<?php
$contentType = 'text/xml; charset=UTF-8';

// create feed document
$feedClient = new \DoubleBreak\Spapi\Api\Feeds($cred, $config);
$response = $feedClient->createFeedDocument(["contentType" => $contentType]);
echo $payload = $response['payload'];

$feedContentFilePath = './sample.xml';

$result = (new \DoubleBreak\Spapi\Helper\Feeder())->uploadFeedDocument($payload,$contentType,$feedContentFilePath);
echo "<pre>";
print_r($result);

Please assist on this Thanks in Advance!

lyubo-slavilov commented 2 years ago

Hi there, can you encapsulate your actual call to uploadFeedDocument() in a try-catch? Then you can examine what is the exact exception and the reason your request is failing

You can see this section in the README https://github.com/double-break/spapi-php#debugging-responses

jsanthoshaws commented 2 years ago

Hi Iyubo,

Thanks below is the error i am getting can you please assist

Unexpected exception: cURL error 3: (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

`try {
   $result = (new \DoubleBreak\Spapi\Helper\Feeder())->uploadFeedDocument($payload,$contentType,$feedContentFilePath);
echo "<pre>";
print_r($result);

  } catch (\GuzzleHttp\Exception\ClientException $e) {
    $httpCode = $e->getResponse()->getStatusCode();
    $errorBody =  $e->getResponse()->getBody();

    echo "Amazon SP API responded with HTTP {$httpCode}\n {$errorBody}";

  } catch(\Exception $e) {
    echo "Unexpected exception: " . $e->getMessage();
  }

`

jsanthoshaws commented 2 years ago

Please correct me if i am wrong , i am trying to update inventory using the below script where in i am getting response array with [feedDocumentId] and [url] when calling the function

$response = $feedClient->createFeedDocument(["contentType" => $contentType]);

but when i am trying to call the function uploadFeedDocument i am getting the below curl error Unexpected exception: cURL error 3: (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

$result = (new \DoubleBreak\Spapi\Helper\Feeder())->uploadFeedDocument($payload,$contentType,$feedContentFilePath);

<?php

// create feed document
$feedClient = new \DoubleBreak\Spapi\Api\Feeds($cred, $config);
$response = $feedClient->createFeedDocument(["contentType" => $contentType]);
$payload = $response['payload'];  // please note $payload is empty null but on response array i am getting [feedDocumentId] and [url]

$feedContentFilePath = './sample.xml';

try {
   $result = (new \DoubleBreak\Spapi\Helper\Feeder())->uploadFeedDocument($payload,$contentType,$feedContentFilePath);  

echo "<pre>";
print_r($result);

  } catch (\GuzzleHttp\Exception\ClientException $e) {
    $httpCode = $e->getResponse()->getStatusCode();
    $errorBody =  $e->getResponse()->getBody();

    echo "Amazon SP API responded with HTTP {$httpCode}\n {$errorBody}";

  } catch(\Exception $e) {
    echo "Unexpected exception: " . $e->getMessage();
  }
lyubo-slavilov commented 2 years ago

@jsanthoshaws

Regarding the payload, SPAPI is not consistent, so you can access your identifiers directly, instead of looking for them in the payload

About the CURL error, can you add 'http' => ['debug' =>true] to your configuration and check what is the URL the request is made to?

May be there is a problem with this particular client. I have never used it.

fangdashng commented 2 years ago

hi, I have a question,
what`s the the file named .aws-tokens ? where download or created by myself?

lyubo-slavilov commented 2 years ago

@fangdashng This file is not downloaded, but it is automatically generated when initializing spapi-php library.

//Create token storage which will store the temporary tokens
  $tokenStorage = new DoubleBreak\Spapi\SimpleTokenStorage('./aws-tokens');

The purpose is to cache the access tokens which are obtained from Amazon. This file MUST BE ignored in your repository

spapi-php provides TokenStorageInterface. You can implement your own token storage if you wish.

fangdashng commented 2 years ago

@fangdashng This file is not downloaded, but it is automatically generated when initializing spapi-php library.

//Create token storage which will store the temporary tokens
  $tokenStorage = new DoubleBreak\Spapi\SimpleTokenStorage('./aws-tokens');

The purpose is to cache the access tokens which are obtained from Amazon. This file MUST BE ignored in your repository

spapi-php provides TokenStorageInterface. You can implement your own token storage if you wish.

thanks, I already know

lyubo-slavilov commented 2 years ago

Closing due to inactivity on the original topic