【问题标题】:Submit an Amazon MWS GetMyFeesEstimate API Request提交亚马逊 MWS GetMyFeesEstimate API 请求
【发布时间】:2017-03-25 01:12:18
【问题描述】:

我正在尝试使用亚马逊 MWS API 检索特定 SKU 的费用估算。我有示例文件并已阅读并阅读,但我不知道如何实际指定要提交的 SKU。

我有针对模拟文件的示例文件 GetMyFeesEstimateSample.php,但那是响应文件,不是吗?

这是我所拥有的,如何为请求指定 SellerSKU?

<?php
/*******************************************************************************
 * Copyright 2009-2016 Amazon Services. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 *
 * You may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 * specific language governing permissions and limitations under the License.
 *******************************************************************************
 * PHP Version 5
 * @category Amazon
 * @package  Marketplace Web Service Products
 * @version  2011-10-01
 * Library Version: 2016-06-01
 * Generated: Fri Sep 16 11:49:32 PDT 2016
 */

/**
 * Get My Fees Estimate Sample
 */

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

/************************************************************************
 * Instantiate Implementation of MarketplaceWebServiceProducts
 *
 * AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
 * are defined in the .config.inc.php located in the same
 * directory as this sample
 ***********************************************************************/
// 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);

/************************************************************************
 * Uncomment to try out Mock Service that simulates MarketplaceWebServiceProducts
 * responses without calling MarketplaceWebServiceProducts service.
 *
 * Responses are loaded from local XML files. You can tweak XML files to
 * experiment with various outputs during development
 *
 * XML files available under MarketplaceWebServiceProducts/Mock tree
 *
 ***********************************************************************/
 // $service = new MarketplaceWebServiceProducts_Mock();

/************************************************************************
 * Setup request parameters and uncomment invoke to try out
 * sample for Get My Fees Estimate Action
 ***********************************************************************/
 // @TODO: set request. Action can be passed as MarketplaceWebServiceProducts_Model_GetMyFeesEstimate
 $request = new MarketplaceWebServiceProducts_Model_GetMyFeesEstimateRequest();
 $request->setSellerId(MERCHANT_ID);
 // object or array of parameters
 invokeGetMyFeesEstimate($service, $request);

/**
  * Get Get My Fees Estimate Action Sample
  * Gets competitive pricing and related information for a product identified by
  * the MarketplaceId and ASIN.
  *
  * @param MarketplaceWebServiceProducts_Interface $service instance of MarketplaceWebServiceProducts_Interface
  * @param mixed $request MarketplaceWebServiceProducts_Model_GetMyFeesEstimate or array of parameters
  */

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

我找到了这个,但我仍然不知道该怎么做。您会认为亚马逊样品将包含样品 ASIN 或 SKU; https://docs.developer.amazonservices.com/en_US/products/Products_GetMyFeesEstimate.html

【问题讨论】:

    标签: php amazon-mws


    【解决方案1】:

    昨天正在编程并找到解决方案,以获取有关 FeesEstimateRequestElements 的更多信息:

    http://docs.developer.amazonservices.com/en_US/products/Products_Datatypes.html#FeesEstimateRequest

    GetMyFeesEstimate 操作信息:

    http://docs.developer.amazonservices.com/en_US/products/Products_GetMyFeesEstimate.html

    GetMyFeesEstimateSample 与一些 cmets,这有效:

    <?php
    
    require_once('.config.inc.php');
    
    
    $serviceUrl = "https://mws.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);
    
    
    //First we set up all the list variables 
    $FeesEstimateRequest = new MarketplaceWebServiceProducts_Model_FeesEstimateRequest();
    $FeesEstimateRequest->setMarketplaceId('ATVPDKIKX0DER'); // Amazon.com marketplace id
    $FeesEstimateRequest->setIdType('SellerSKU');             // IdType values: ASIN, SellerSKU, SellerSKU in your case
    $FeesEstimateRequest->setIdValue('XXXXXXXXXX');       // The value of the id you have entered
    $FeesEstimateRequest->setIdentifier('request1');          // A identifier for the item you have requested, this is for your own use 
    $FeesEstimateRequest->setIsAmazonFulfilled(FALSE);        // Fullfilled by Amazon? true if the offer is fulfilled by Amazon.    
    
    //To set up the $PriceToEstimateFees object we need two instances of the object MarketplaceWebServiceProducts_Model_MoneyType
    //@ set up for both cases: Listing Price and Shipping Price  
    //New object MoneyType, setting up the currency and amount for listing price
    $MoneyTypeListingPrice = new MarketplaceWebServiceProducts_Model_MoneyType();
    $MoneyTypeListingPrice->setCurrencyCode('USD'); // String, the currency code of the price : USD in this example for amazon.com marketplace
    $MoneyTypeListingPrice->setAmount('0.00');      // String, the price of the item 
    
    //New object MoneyType, setting up the currency and amount for shipping price
    $MoneyTypeShipping = new MarketplaceWebServiceProducts_Model_MoneyType();
    $MoneyTypeShipping->setCurrencyCode('USD'); // String, the currency code of the price : USD in this example for amazon.com marketplace
    $MoneyTypeShipping->setAmount('0.00');       // String, the price of the item 
    
    //Setting up the prices: Listing Price and Shipping Price
    $PriceToEstimateFees = new MarketplaceWebServiceProducts_Model_PriceToEstimateFees();
    $PriceToEstimateFees->setListingPrice($MoneyTypeListingPrice);
    $PriceToEstimateFees->setShipping($MoneyTypeShipping);
    
    //Finally setting up the $PriceToEstimateFees object to the $FeesEstimateRequest object 
    $FeesEstimateRequest->setPriceToEstimateFees($PriceToEstimateFees); // The product price that the fee estimate is based on. 
    
    //setting up the final required parameter in the $FeesEstimateRequestList object
    $FeesEstimateRequestList = new MarketplaceWebServiceProducts_Model_FeesEstimateRequestList();
    $FeesEstimateRequestList->setFeesEstimateRequest($FeesEstimateRequest);
    
    // Last step : sending the $FeesEstimateRequestList object into $request
    $request = new MarketplaceWebServiceProducts_Model_GetMyFeesEstimateRequest();
    $request->setSellerId(MERCHANT_ID);
    $request->setFeesEstimateRequestList($FeesEstimateRequestList);
    // object or array of parameters
    invokeGetMyFeesEstimate($service, $request);
    
    
    
     function invokeGetMyFeesEstimate(MarketplaceWebServiceProducts_Interface $service, $request)
      {
      try {
        $response = $service->GetMyFeesEstimate($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");
     }
    }
    

    【讨论】:

    • 这是有帮助的吗?
    【解决方案2】:

    作为请求的一部分,您提交FeesEstimateRequestList 在该列表中,您指定IdType,可以是ASINSellerSKU。然后在IdValue 中给它一个值。请注意,还有其他元素是必需的。在这里查看FeesEstimateRequest 中的这些元素https://docs.developer.amazonservices.com/en_US/products/Products_Datatypes.html#FeesEstimateRequest

    您上面的 POST 定义了一个 ASIN,而不是为 IdType 定义的 SellerSKU。只需像我上面提到的那样将其更改为 SellerSKU 即可。

    我使用C# SDK,其中包含所有这些示例。我会假设PHP SDK 是一样的,但也许它是完整的。在任何情况下,您都需要在您的 POST 中提交 FeesEstimateRequestList,以便 MWS 知道您在寻找什么。

    【讨论】:

    • 对不起,截图来自亚马逊网站,不是我的要求。这是我很难理解的一点,我如何形成和提交请求。我将在一个循环中运行多个请求。
    • 我不是 php 人,但最终结果是生成一个 POST 到 MWS。您可以手动对其进行编码并提交或使用亚马逊的 SDK。查看上面的 PHP 代码,您似乎需要取消注释此行:“* @param mixed $request MarketplaceWebServiceProducts_Model_GetMyFeesEstimate 或参数数组”并将您的参数放在那里。这对我来说有点陌生。看看stackoverflow的例子。也许这个:stackoverflow.com/questions/37416063/…
    猜你喜欢
    • 1970-01-01
    • 2018-12-29
    • 2017-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多