Fetch product from amazon mws using product api

2019-06-10 15:00发布

问题:

I have successfully posted product in amazon using amazon MWS Feeds API. Now i want to list those products using the Products API, But im facing some errors. I run GetMatchingProductSample.php.

Caught Exception: Required parameter ASINList not found Response Status Code: 400 Error Code: MissingParameter Error Type: Sender Request ID: 8bb9c8d1-f48c-495c-be86-89492976b4a9 XML: SenderMissingParameterRequired parameter ASINList not found8bb9c8d1-f48c-495c-be86-89492976b4a9 ResponseHeaderMetadata: RequestId: 8bb9c8d1-f48c-495c-be86-89492976b4a9

Code:

<?php
require_once('.config.inc.php');

$serviceUrl = "https://mws-eu.amazonservices.com/Products/2011-10-01";


$config = array (
  'ServiceURL' => $serviceUrl,
  'ProxyHost' => null,
  'ProxyPort' => -1,
  'ProxyUsername' => null,
  'ProxyPassword' => null,
  'MaxErrorRetry' => 3,
);

$service = new MarketplaceWebServiceProducts_Client(
      AWS_ACCESS_KEY_ID,
      AWS_SECRET_ACCESS_KEY,
      APPLICATION_NAME,
      APPLICATION_VERSION,
      $config);
$request = new MarketplaceWebServiceProducts_Model_GetMatchingProductRequest();
$request->setSellerId(MERCHANT_ID);
// object or array of parameters
invokeGetMatchingProduct($service, $request);

function invokeGetMatchingProduct(MarketplaceWebServiceProducts_Interface $service, $request)
{
    try {
      $response = $service->GetMatchingProduct($request);

      echo ("Service Response\n");
      echo ("=============================================================================\n");

      $dom = new DOMDocument();
      $dom->loadXML($response->toXML());
      $dom->preserveWhiteSpace = false;
      $dom->formatOutput = true;
      echo $dom->saveXML();
      echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");

   } catch (MarketplaceWebServiceProducts_Exception $ex) {
      echo("Caught Exception: " . $ex->getMessage() . "\n");
      echo("Response Status Code: " . $ex->getStatusCode() . "\n");
      echo("Error Code: " . $ex->getErrorCode() . "\n");
      echo("Error Type: " . $ex->getErrorType() . "\n");
      echo("Request ID: " . $ex->getRequestId() . "\n");
      echo("XML: " . $ex->getXML() . "\n");
      echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
   }
}

回答1:

As it says ASINList not found

You need to add these line of code after below line

$request->setSellerId(MERCHANT_ID);

Code needs to add:

$request->setMarketplaceId($marketplace_id);
$asin_list = new MarketplaceWebServiceProducts_Model_ASINListType();
$asins = array("ASIN1","ASIN2","ASIN3");
$asin_list->setASIN($asins);
$request->setASINList($asin_list);