I don't get prices with Amazon Product Advertising API
Asked Answered
H

7

8

I try to get prices of an ASIN number with the Amazon Product Advertising API.

Code:

    $artNr = "B003TKSD8E";
    $base_url = "http://ecs.amazonaws.de/onca/xml";
    $params = array(
        'AWSAccessKeyId' => self::API_KEY,
        'AssociateTag' => self::API_ASSOCIATE_TAG,
        'Version' => "2010-11-01",
        'Operation' => "ItemLookup",
        'Service' => "AWSECommerceService",
        'Condition' => "All",
        'IdType' => 'ASIN',
        'ItemId' => $artNr);

        
    $params['Timestamp'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
     
    $url_parts = array();
    foreach(array_keys($params) as $key)
        $url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key]));
    sort($url_parts);
     
    $url_string = implode("&", $url_parts);
    $string_to_sign = "GET\necs.amazonaws.de\n/onca/xml\n" . $url_string;

    $signature = hash_hmac("sha256", $string_to_sign, self::API_SECRET, TRUE);
    
    $signature = urlencode(base64_encode($signature));
     
    $url = $base_url . '?' . $url_string . "&Signature=" . $signature;
        
    $response = file_get_contents($url);
    $parsed_xml = simplexml_load_string($response);

I think this should be correct - but I don't get offers in the response:

<?xml version="1.0" ?>
  <ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2010-11-01">
    <OperationRequest>
      <RequestId>*********************</RequestId>
      <Arguments>
        <Argument Name="Condition" Value="All">
      </Argument>
        <Argument Name="Operation" Value="ItemLookup">
      </Argument>
        <Argument Name="Service" Value="AWSECommerceService">
      </Argument>
        <Argument Name="ItemId" Value="B003TKSD8E">
      </Argument>
        <Argument Name="IdType" Value="ASIN">
      </Argument>
        <Argument Name="AWSAccessKeyId" Value="*********************">
      </Argument>
        <Argument Name="Timestamp" Value="2011-11-29T01:49:01.000Z">
      </Argument>
        <Argument Name="Signature" Value="*********************">
      </Argument>
        <Argument Name="AssociateTag" Value="*********************">
      </Argument>
        <Argument Name="Version" Value="2010-11-01">
      </Argument>
    </Arguments>
      <RequestProcessingTime>0.0083130000000000</RequestProcessingTime>
    </OperationRequest>
    <Items>
      <Request>
        <IsValid>True</IsValid>
        <ItemLookupRequest>
          <Condition>All</Condition>
          <IdType>ASIN</IdType>
          <ItemId>B003TKSD8E</ItemId>
          <ResponseGroup>Small</ResponseGroup>
          <VariationPage>All</VariationPage>
        </ItemLookupRequest>
      </Request>
      <Item>
        <ASIN>B003TKSD8E</ASIN>
        <DetailPageURL>http://www.amazon.de/Apple-iPhone-4-32GB-schwarz/dp/B003TKSD8E%3FSubscriptionId%3DAKIAI6NFQHK2DQIPRUEQ%26tag%3Dbanholzerme-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB003TKSD8E</DetailPageURL>
        <ItemLinks>
          <ItemLink>
            <Description>Add To Wishlist</Description>
            <URL>http://www.amazon.de/gp/registry/wishlist/add-item.html%3Fasin.0%3DB003TKSD8E%26SubscriptionId%3DAKIAI6NFQHK2DQIPRUEQ%26tag%3Dbanholzerme-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12738%26creativeASIN%3DB003TKSD8E</URL>
          </ItemLink>
          <ItemLink>
            <Description>Tell A Friend</Description>
            <URL>http://www.amazon.de/gp/pdp/taf/B003TKSD8E%3FSubscriptionId%3DAKIAI6NFQHK2DQIPRUEQ%26tag%3Dbanholzerme-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12738%26creativeASIN%3DB003TKSD8E</URL>
          </ItemLink>
          <ItemLink>
            <Description>All Customer Reviews</Description>
            <URL>http://www.amazon.de/review/product/B003TKSD8E%3FSubscriptionId%3DAKIAI6NFQHK2DQIPRUEQ%26tag%3Dbanholzerme-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12738%26creativeASIN%3DB003TKSD8E</URL>
          </ItemLink>
          <ItemLink>
            <Description>All Offers</Description>
            <URL>http://www.amazon.de/gp/offer-listing/B003TKSD8E%3FSubscriptionId%3DAKIAI6NFQHK2DQIPRUEQ%26tag%3Dbanholzerme-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D12738%26creativeASIN%3DB003TKSD8E</URL>
          </ItemLink>
        </ItemLinks>
        <ItemAttributes>
          <Manufacturer>Apple Computer</Manufacturer>
          <ProductGroup>CE</ProductGroup>
          <Title>Apple iPhone 4 32GB schwarz</Title>/ItemAttributes>
        </Item>
      </Items>
    </ItemLookupResponse>

Why don't I get any price-information?

Hoe answered 29/11, 2011 at 1:34 Comment(3)
fyi: it's ASIN - amazon standard identification number. ANSI is american national standards institute.Palingenesis
Try echo $parsed_xml->asXML(); instead of print_r because print_r does not show the whole picture with SimpleXML.Sesquipedalian
@Sesquipedalian I changed the response - the price wasn't hiddenHoe
O
22

To get prices for an item you need to include a ResponseGroup parameter of Offers or OfferFull and a MerchantId parameter of All:

$params = array(
    'AWSAccessKeyId' => self::API_KEY,
    'AssociateTag' => self::API_ASSOCIATE_TAG,
    'Version' => "2010-11-01",
    'Operation' => "ItemLookup",
    'Service' => "AWSECommerceService",
    'Condition' => "All",
    'IdType' => 'ASIN',
    'ResponseGroup' => 'Offers',                <- important
    'MerchantId' => 'All',                      <- important
    'ItemId' => $artNr);

If you don't include the MerchantId of All you will only get offer listings for Amazon (the default MerchantId). This will return the offer listings and your response will include something like the following:

<Items>
    ...
    <Item>
        ...
        <Offers>
            ...
            <Offer>
                ...
                <OfferListing>
                    <Price>
                        <Amount>1350</Amount>
                        <CurrencyCode>USD</CurrencyCode>
                        <FormattedPrice>$13.50</FormattedPrice>
                    </Price>
                    ...
                </OfferListing>
                ...
            </Offer>
       ...

See the documentation for the Offers Response Group for more information. Also see the Response Group request parameter description for the ItemLookup operation for more valid Response Groups.

Omnipotent answered 29/11, 2011 at 8:3 Comment(5)
Thank you very much, that was the solution!Hoe
I'm also facing the same issue and the ResponseGroup and MarchentId solution is not working for me. The differences are, 1) my version is "2011-08-01" 2) I'm using Java to implement it. Another issue I noticed is, even if I pass ResponseGroup=Medium, it shows <ResponseGroup>Small</ResponseGroup> in the response. Is there any other alternative for it?Elliot
@Elliot No, I don't believe so. It's been a while since I've worked with this so I don't have any current info.Omnipotent
@JonathanSpooner, Yes it is working! the issue was some of the products returned from Amazon does not have price details.Elliot
The only valid option for MerchantId is "Amazon". So maybe they made "All" the default. docs.aws.amazon.com/AWSECommerceService/latest/DG/…Efta
O
3

I suggest you use the OfferSummary response Group which will return something like this: ...

["Items"]=> object(stdClass)#72 (2) { 
    ... 
    ["Item"]=> object(stdClass)#75 (2) {
        ["ASIN"]=> string(10) "1405910232" 
        ["OfferSummary"]=> object(stdClass)#76 (6) { 
            ["LowestNewPrice"]=> object(stdClass)#77 (3) {  
                ["Amount"]=> int(247) 
                ["CurrencyCode"]=> string(3) "GBP" 
                ["FormattedPrice"]=> string(6) "£2.47" 
            } 
            ["LowestUsedPrice"]=> object(stdClass)#78 (3) {
                ["Amount"]=> int(297) 
                ["CurrencyCode"]=> string(3) "GBP" 
                ["FormattedPrice"]=> string(6) "£2.97" 
            }

...

Oakleil answered 10/9, 2012 at 22:5 Comment(0)
C
3

Use "medium" for "ResponseGroup" parameter, allowed values small, medium and large. small response will not have the price details.

http://docs.aws.amazon.com/AWSECommerceService/latest/DG/RG_Small.html

Clemens answered 24/1, 2013 at 13:7 Comment(1)
The ResponseGroup=Small/Medium/Large all I tried but still it returns <ResponseGroup>Small</ResponseGroup> and no price details. Do you have any other thoughts about it?Elliot
L
2

Xarem, please, take a look at Product Advertising API (API Reference/Operations). You've requested ItemLookup operation and the price was not promissed for you. Use SellerListingLookup (or some other) operation to get available prices. This is quit understandable, because Amazon has a big pool of sellers and prices differ from one to another, so they can't provide prices for items, but for item-seller pairs.

Lytta answered 29/11, 2011 at 2:26 Comment(1)
Unfortunately, SellerListingLookup is not available anymore in (new) Product Advertising API.Schindler
L
2

Had I enough rep I'd have commented on an earlier solution but alas I'm limited to providing a new answer...

So, if you pass a MerchantId value of All, you will see this in your response:

<MerchantId>Deprecated</MerchantId>

which indicates to me that perhaps you should not provide this parameter, counter to what the selected answer suggests.

More than that, I suspect there is something else going on. I'll probably pose a whole new question about this here, but I am submitting a request for a product with a valid ASIN, getting back True, requesting the response groups Offers, OfferFull, and OfferSummary, and I am not getting back any price information. Yet when I look at the very same product on amazom.com, I see see price information.

So something else could be wrong here.

Locris answered 16/10, 2012 at 20:21 Comment(0)
U
0

You can use parser from associate script to answer your question.

Upholsterer answered 30/1, 2013 at 13:19 Comment(0)
I
0

Edit your response group like as below: responseGroup('Medium,OfferSummary,VariationSummary')

In response group you will get the key "VariationSummary" and inside this object you can check below params for price :

  • LowestPrice
  • HighestPrice
  • LowestSalePrice
  • HighestSalePrice

Note that you may not get all above 4 params in VariationSummary object.

Incomprehensible answered 16/2, 2017 at 14:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.