amazon product advertising api get product with offers

1.7k Views Asked by At

I am using Amazon product advertising API. I want get product which has offer.

I tried the amazon-api php class to get the data, but it doesn't work properly.

Need Help to get the products which has an offer.

    <?php

    require_once 'aws_signed_request.php';

class AmazonProductAPI
    {

  private $public_key     = "YOUR AMAZON ACCESS KEY ID";
  private $private_key    = "YOUR AMAZON SECRET KEY";

/* 'Associate Tag' now required, effective from 25th Oct. 2011 */
private $associate_tag  = "YOUR AMAZON ASSOCIATE TAG";

const MUSIC = "Music";
const DVD   = "DVD";
const GAMES = "VideoGames";

  private function verifyXmlResponse($response)
   {
    if ($response === False)
    {
        throw new Exception("Could not connect to Amazon");
    }
    else
    {
        if (isset($response->Items->Item->ItemAttributes->Title))
        {
            return ($response);
        }
        else
        {
            throw new Exception("Invalid xml response.");
        }
    }
    }

  private function queryAmazon($parameters)
   {
    return aws_signed_request("com",
                              $parameters,
                              $this->public_key,
                              $this->private_key,
                              $this->associate_tag);
}

public function searchProducts($search,$category,$searchType="UPC")
{
    $allowedTypes = array("UPC", "TITLE", "ARTIST", "KEYWORD");
    $allowedCategories = array("Music", "DVD", "VideoGames");

    switch($searchType) 
    {
        case "UPC" :
            $parameters = array("Operation"     => "ItemLookup",
                                "ItemId"        => $search,
                                "SearchIndex"   => $category,
                                "IdType"        => "UPC",
                                "ResponseGroup" => "Medium");
                        break;

        case "TITLE" :
            $parameters = array("Operation"     => "ItemSearch",
                                "Title"         => $search,
                                "SearchIndex"   => $category,
                                "ResponseGroup" => "Offers");
                        break;

    }

    $xml_response = $this->queryAmazon($parameters);

    return $this->verifyXmlResponse($xml_response);

}

}

any help would be appreciated.

1

There are 1 best solutions below

1
On

I know its pretty late but I came across this post recently.

First of all you need to clarify how you are making a request to amazon product advertising API as there might be several reasons, you are not getting proper response object. PHP Code base( previously ECS ) may help you to initiate properly.

Regarding Offers - when you get the "itemlookup" response there is keys "OfferSummary" and "Offers" which provide you available offers details for the requested product( ASIN for which you have initiated itemLookup).