GetLowestPricedOffersForSKU failed processing arguments

痞子三分冷 提交于 2020-01-03 09:17:44

问题


I have a slight issue when trying to call GetLowestPricedOffersForSKU, I get the response :

Failed processing arguments of org.jboss.resteasy.spi.metadata

I can call other functions in the Product Api and they work fine, just get the above error on this function.

I have looked round the net for the answer but can't find anything that is related to this, does anybody have any idea why I'm getting this ?

By the way it all works fine in the MWS Scratchpad !


回答1:


Posting in case anyone else comes to this and is as confused as I was. There is a fundamental difference with how nearly all Amazon MWS requests work except this particular one. All other requests technically accept the parameters as query parameters instead of POST data. The scratchpad even suggests this is how it is actually working (although the MWS Scratchpad actually sends the data as Post Data Fields also).




回答2:


MWS needs the POST data passed as form params instead of as a query string for some operations. Otherwise, it pukes a Failed processing arguments of org.jboss.resteasy.spi.metadata style 400 Bad Request error for some operations such as this one (GetMyFeesEstimate is another that suffers from this).

For instance, if you did the following POST request in Guzzle 6 then you'd likely get the error:

$response = $client->request('POST', 'https://mws.amazonservices.com/Products/2011-10-01/?AWSAccessKeyId=YOURAWSACCESSKEY&Action=GetLowestPricedOffersForASIN&SellerId=YOURSELLERID&MWSAuthToken=amzn.mws.fghsffg-4t44e-hfgh-dfgd-zgsdbfe5erg&SignatureVersion=2&Timestamp=2017-07-09T15%3A45%3A18%2B00%3A00&Version=2011-10-01&Signature=bCasdxXmYDCasdaXBhsdgse4pQ6hEbevML%2FJvzdgdsfdy2o%3D&SignatureMethod=HmacSHA256&MarketplaceId=ATVPDKIKX0DER&ASIN=B007EZK19E');

To fix this you'd submit it as form data as in this Guzzle 6 example:

$response = $client->request('POST', 'https://mws.amazonservices.com/Products/2011-10-01', [
    'form_params' => [
        'AWSAccessKeyId' => 'YOURAWSACCESSKEY',
        'Action' => 'GetLowestPricedOffersForASIN',
        'SellerId' => 'YOURSELLERID',
        'MWSAuthToken' => 'amzn.mws.fghsffg-4t44e-hfgh-dfgd-zgsdbfe5erg',
        'SignatureVersion' => 2,
        'Timestamp' => '2017-07-09T15%3A45%3A18%2B00%3A00',
        'Version' => '2011-10-01',
        'Signature' => 'bCasdxXmYDCasdaXBhsdgse4pQ6hEbevML%2FJvzdgdsfdy2o%3D',
        'SignatureMethod' => 'HmacSHA256',
        'MarketplaceId' => 'ATVPDKIKX0DER',
        'ASIN' => 'B007EZK19E',
    ]
]);



回答3:


This code worked for me. Hope it will help someone.

<?php

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

    // More endpoints are listed in the MWS Developer Guide
    // North America:
    $serviceUrl = "https://mws.amazonservices.com/Products/2011-10-01";
    // Europe
    //$serviceUrl = "https://mws-eu.amazonservices.com/Products/2011-10-01";
    // Japan
    //$serviceUrl = "https://mws.amazonservices.jp/Products/2011-10-01";
    // China
    //$serviceUrl = "https://mws.amazonservices.com.cn/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);


     // @TODO: set request. Action can be passed as MarketplaceWebServiceProducts_Model_GetLowestPricedOffersForSKU
     $request = new MarketplaceWebServiceProducts_Model_GetLowestPricedOffersForSKURequest();
     $request->setSellerId(MERCHANT_ID);
     $request->setMWSAuthToken(MWSAUTH_TOKEN);
     $request->setMarketplaceId(MARKETPLACE_ID);
     $request->setSellerSKU($sellerSKU);
     $request->setItemCondition($ItemCondition);
     // object or array of parameters
     invokeGetLowestPricedOffersForSKU($service, $request);


      function invokeGetLowestPricedOffersForSKU(MarketplaceWebServiceProducts_Interface $service, $request)
      {
          try {
            $response = $service->GetLowestPricedOffersForSKU($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");
         }
     }
    ?>


来源:https://stackoverflow.com/questions/36293752/getlowestpricedoffersforsku-failed-processing-arguments

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!