c# - 如何使用亚马逊网络服务获取 "The Offer Listing"?

标签 c# amazon-web-services amazon-mws

我想使用亚马逊 API 获取“offer-listing”。 我自己探索过,但没有得到它的线索。 如果有人向我建议 API 端点以获取报价列表或替代方案,那就太好了

最佳答案

您可以取消产品页面或使用亚马逊产品的 API 并调用:

  1. GetLowestOfferListingsForSKU 获取包含您自己的报价列表(您可以使用 $request->setExcludeMe(TRUE) 排除您自己)
  2. GetMyPriceForSKU 仅获取您的报价 list

此 API 调用将返回着陆价格、运费、 list 价格,其中着陆价格是您的销售价格 + 运费。以上 API 调用均不包含卖家名称或任何身份,因此如果您需要卖家名称和售价,最好取消产品页面。

这是我使用的代码:

$asin amazon product's ASIN
$sku is amazon product's SKU
$pos_data array contains all Amazon API's credentials
$fba_check is 'Y' or 'N' whether the ASIN is FBA(Fulfilled by Amazon) or not

function init_pro_api($asin, $sku, $pos_data, $fba_check)
{
    $try = 0;
    while($try < 2)
    {
        $offers_list = "";
        $AWS_ACCESS_KEY_ID = $pos_data['azn_access_key'];
        $AWS_SECRET_ACCESS_KEY = $pos_data['azn_secret_access_key'];
        $APPLICATION_NAME = $pos_data['azn_app_name'];
        $APPLICATION_VERSION = $pos_data['azn_app_version'];
        $MERCHANT_ID = $pos_data['azn_merchant_id'];
        $MARKETPLACE_ID = $pos_data['azn_marketplace_id'];
        $platform = $pos_data['azn_platform_variant'];


        if($platform == "uk")
        {
            $serviceURL = "https://mws.amazonservices.co.uk/Products/2011-10-01";
        }
        else
            $serviceURL = "https://mws-eu.amazonservices.com/Products/2011-10-01";

        $DATE_FORMAT = "Y-m-d";

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

        $service = new MarketplaceWebServiceProducts_Client($AWS_ACCESS_KEY_ID, $AWS_SECRET_ACCESS_KEY, $APPLICATION_NAME, $APPLICATION_VERSION, $config);

        // Get My Price
        $request = new MarketplaceWebServiceProducts_Model_GetMyPriceForSKURequest();
        $request->setSellerId($MERCHANT_ID);
        $request->setMarketplaceId($MARKETPLACE_ID);

        $sku_list = new MarketplaceWebServiceProducts_Model_SellerSKUListType();
        $sku_list->setSellerSKU($sku);
        $request->setSellerSKUList($sku_list);

        $my_offer = invokeGetMyPriceForSKU($service, $request, $fba_check);

        // Get Other Sellers Lowest Offering Price
        $request = new MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForSKURequest();
        $request->setSellerId($MERCHANT_ID);
        $request->setMarketplaceId($MARKETPLACE_ID);
        $request->setItemCondition("New");
        $request->setExcludeMe(TRUE);

        $sku_list = new MarketplaceWebServiceProducts_Model_SellerSKUListType();
        $sku_list->setSellerSKU($sku);
        $request->setSellerSKUList($sku_list);

        $other_low_offers = invokeGetLowestOfferListingsForSKU($service, $request);

        if($my_offer != "" or $my_offer != NULL)
        {
            $offers_list["MyOffer"] = $my_offer;
        }

        if($other_low_offers != "" or $other_low_offers != NULL)
        {
            $offers_list["OtherOffer"] = $other_low_offers;
        }

        if(isset($offers_list["OtherOffer"][0]))
            if($offers_list["OtherOffer"][0] != "")
                break;
        $try++;
    }
    return $offers_list;
}
function invokeGetMyPriceForSKU(MarketplaceWebServiceProducts_Interface $service, $request, $fba_check)
{
    try
    {
        $my_response_data = "";
        $pre_check_xml_data = array();
        $xml_feed_counter = 0;
        $response = $service->GetMyPriceForSKU($request);

        $dom = new DOMDocument();
        $dom->loadXML($response->toXML());
        $dom->preserveWhiteSpace = false;
        $dom->formatOutput = true;
        $xml_data = $dom->saveXML();

        $doc = new DOMDocument;
        $doc->preserveWhiteSpace = FALSE;
        $doc->loadXML($xml_data);
        $offer_length = $doc->getElementsByTagName('Offer')->length;
        $fba_index = "";
        $normal_index = "";

        for($o = 0; $o < $offer_length; $o++)
        {
            $pre_check_xml_data[$o]["LandedPrice"] = $doc->getElementsByTagName('LandedPrice')->item($o)->lastChild->nodeValue;
            $pre_check_xml_data[$o]["ListingPrice"] = $doc->getElementsByTagName('ListingPrice')->item($o)->lastChild->nodeValue;
            $pre_check_xml_data[$o]["Shipping"] = $doc->getElementsByTagName('Shipping')->item($o)->lastChild->nodeValue;
            $pre_check_xml_data[$o]["FulfillmentChannel"] = $doc->getElementsByTagName('FulfillmentChannel')->item($o)->nodeValue;
            if($fba_check == "Y")
            {
                if($doc->getElementsByTagName('FulfillmentChannel')->item($o)->nodeValue == "AMAZON")
                {
                    $fba_index = $o;
                    break;
                }
            }
            elseif($fba_check == "N")
            {
                if($doc->getElementsByTagName('FulfillmentChannel')->item($o)->nodeValue == "MERCHANT")
                {
                    $normal_index = $o;
                    break;
                }
            }
        }
        if($fba_check == "Y")
        {
            if($fba_index === "")
            {
                $my_response_data[0]["LandedPrice"] = "";
                $my_response_data[0]["ListingPrice"] = "";
                $my_response_data[0]["Shipping"] = "";
                $my_response_data[0]["Fulfillment"] = "";
                return $my_response_data;
            }
            else
            {
                $my_response_data[0] = $pre_check_xml_data[$fba_index];
                return $my_response_data;
            }
        }
        else
        {
            $my_response_data[0] = $pre_check_xml_data[$normal_index];
            return $my_response_data;
        }
    }
    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");
    }
}
function invokeGetLowestOfferListingsForSKU(MarketplaceWebServiceProducts_Interface $service, $request)
{
    try
    {
        $response_data = "";
        $counter = 0;
        $response = $service->getLowestOfferListingsForSKU($request);

        $getLowestOfferListingsForSKUResultList = $response->getGetLowestOfferListingsForSKUResult();
        foreach($getLowestOfferListingsForSKUResultList as $getLowestOfferListingsForSKUResult)
        {
            if($getLowestOfferListingsForSKUResult->isSetProduct())
            {
                $product = $getLowestOfferListingsForSKUResult->getProduct();

                if($product->isSetLowestOfferListings())
                {
                    $lowestOfferListings = $product->getLowestOfferListings();
                    $lowestOfferListingList = $lowestOfferListings->getLowestOfferListing();
                    foreach($lowestOfferListingList as $lowestOfferListing)
                    {
                        if($lowestOfferListing->isSetQualifiers())
                        {
                            $qualifiers = $lowestOfferListing->getQualifiers();

                            if($qualifiers->isSetFulfillmentChannel())
                            {
                                $response_data[$counter]["Fulfilled_By"] = $qualifiers->getFulfillmentChannel();
                            }
                            if($qualifiers->isSetShippingTime())
                            {
                                $shippingTime = $qualifiers->getShippingTime();
                                if($shippingTime->isSetMax())
                                {
                                    $response_data[$counter]["ShippingTime"] = $shippingTime->getMax();
                                }
                            }
                        }
                        if($lowestOfferListing->isSetPrice())
                        {
                            $price1 = $lowestOfferListing->getPrice();
                            if($price1->isSetLandedPrice())
                            {
                                $landedPrice1 = $price1->getLandedPrice();
                                if($landedPrice1->isSetAmount())
                                {
                                    $response_data[$counter]["LandedPrice"] = $landedPrice1->getAmount();
                                }
                            }
                            if($price1->isSetListingPrice())
                            {
                                $listingPrice1 = $price1->getListingPrice();
                                if($listingPrice1->isSetAmount())
                                {
                                    $response_data[$counter]["ListingPrice"] = $listingPrice1->getAmount();
                                }
                            }
                            if($price1->isSetShipping())
                            {
                                $shipping1 = $price1->getShipping();
                                if($shipping1->isSetAmount())
                                {
                                    $response_data[$counter]["Shipping"] = $shipping1->getAmount() . "\n";
                                }
                            }
                        }
                        $counter++;
                    }
                }
            }
            if($getLowestOfferListingsForSKUResult->isSetError())
            {
                $error = $getLowestOfferListingsForSKUResult->getError();
                if($error->isSetMessage())
                {
                    $response_data = $error->getMessage() . "\n";
                }
            }
        }
        return $response_data;
    }
    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");
    }
}

关于c# - 如何使用亚马逊网络服务获取 "The Offer Listing"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27934735/

相关文章:

c# - 需要一个在 VB.NET 中使用的 C# 类的工作示例

c# - 使用带有 XML 配置的 log4net 时没有日志文件

c# - StackExchange.Redis的正确使用方法

amazon-web-services - 使用当前日期在 AWS S3 存储桶中创建一个文件夹

amazon-mws - 亚马逊MWS产品API如何检索销售排名和商户名称

c# - System.Reflection 性能

AWS EC2 上的 Node.js RESTful API 服务器与 AWS API 网关

amazon-web-services - AWS CloudFormation 'UserData' 似乎不起作用

python - 亚马逊欧洲 MWS Python Boto 连接访问被拒绝

amazon-mws - 如何通过 MWS/亚马逊报告检索当前的销售价格和日期