double-break / spapi-php

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

upload product feed on sandbox.sellingpartnerapi-na.amazon.com #32

Closed aniruddhaad closed 3 years ago

aniruddhaad commented 3 years ago

Hi, Since production account is not working. I tried using sandbox and got following response while uploading products feed- {"errors":[{"code":"400","message":"Invalid input","details":"Invalid input"}]}

Here is complete output -

Please find attached product XML feed. split-amazon-products-1.txt

canerkoroglu commented 3 years ago

Be carefull closing tag:

document invalid error <?xml version="1.0"?>

if you put a space between " and ? symbols, it should work. <?xml version="1.0" ?>

aniruddhaad commented 3 years ago

Sorry for late reply. The issue was solved by providing proper input to the call. I figured this out after debugging and checking class parameters and amazon documentation.

BTW, there is another bug in the createFeed function. When you pass the json encoded string as input to the function call - PHP Warning: ksort() expects parameter 1 to be array, string given in /var/www/vhosts/w2bshop.com/amz.w2bshop.com/spapi-php/src/Client.php on line 69

koderplus commented 3 years ago

Hi @aniruddhaad i'm still getting same error, Can u please provide correct Product XML Feed ? HEre is the error (i'm using production mode not Sandbox)

upload completely sent off: 200 out of 200 bytes HTTP/1.1 400 Bad Request Date: Fri, 08 Oct 2021 11:56:28 GMT Content-Type: application/json Content-Length: 117 Connection: keep-alive x-amzn-RequestId: 27306ffa-0620-4340-8348-70b1e4ead8ef x-amzn-RateLimit-Limit: 0.0083 x-amz-apigw-id: G4y87EeOoAMFd8Q= X-Amzn-Trace-Id: Root=1-616031ec-04ed798a50c4d1ee67bc5462

Connection #1 to host sellingpartnerapi-na.amazon.com left intact ETHON: performed EASY effective_url=https://sellingpartnerapi-na.amazon.com/feeds/2020-09-04/feeds response_code=400 return_code=ok total_time=0.292145 HTTP response body ~BEGIN~ { "errors": [ { "code": "InvalidInput", "message": "Invalid Input", "details": "" } ] } ~END~

AmzSpApi::ApiError: Error message: the server returns an error HTTP status code: 400 Response headers: {"Date"=>"Fri, 08 Oct 2021 11:56:28 GMT", "Content-Type"=>"application/json", "Content-Length"=>"117", "Connection"=>"keep-alive", "x-amzn-RequestId"=>"27306ffa-0620-4340-8348-70b1e4ead8ef", "x-amzn-RateLimit-Limit"=>"0.0083", "x-amz-apigw-id"=>"G4y87EeOoAMFd8Q=", "X-Amzn-Trace-Id"=>"Root=1-616031ec-04ed798a50c4d1ee67bc5462"} Response body: { "errors": [ { "code": "InvalidInput", "message": "Invalid Input", "details": "" } ] }

any thoughts?

-- Muhammad Ateq

aniruddhaad commented 3 years ago

Hi Muhammad,

Seems like you are using VB. I can not provide code for VB but here is complete code in php -

$tokenStorage = new DoubleBreak\Spapi\SimpleTokenStorage('./aws-tokens');
$signer = new DoubleBreak\Spapi\Signer();
$credentials = new DoubleBreak\Spapi\Credentials($tokenStorage, $signer, $config);
$cred = $credentials->getCredentials();
$contentType = 'text/xml; charset=UTF-8';
// create feed document
$feedClient = new \DoubleBreak\Spapi\Api\Feeds($cred, $config);

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

$feedContentFilePath = './sample.xml';

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

try{
$result=$feedClient->createFeed(json_encode(['feedType'=>'POST_PRODUCT_DATA','marketplaceIds'=>['A2EUQ1WTGCTBG2'],'inputFeedDocumentId'=>$feedDocumentId]));//
var_dump($result);
}
catch (\GuzzleHttp\Exception\ClientException $e) {

  echo "\nLINE NO: ".__LINE__."\n";
  $httpCode = $e->getResponse()->getStatusCode();
  $errorBody =  $e->getResponse()->getBody();

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

}

and here is sample.xml- sample.txt You can rename the extension from txt to xml

Enjoy