Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Product Advertising API - searching for multiple UPCs

Using the Amazon Product Advertising API I am searching for 2 different UPCs:

 // prepare the first ItemSearchRequest
 // prepare a second ItemSearchRequest
 ItemSearchRequest request1 = new ItemSearchRequest();
 request1.SearchIndex = "All";
 //request1.Keywords = table.Rows[i].ItemArray[0].ToString();
 request1.Keywords="9120031340270";
 request1.ItemPage = "1";
 request1.ResponseGroup = new string[] { "OfferSummary" };


 ItemSearchRequest request2 = new ItemSearchRequest();
 request2.SearchIndex = "All";
 //request2.Keywords = table.Rows[i+1].ItemArray[0].ToString();
 request2.Keywords = "9120031340300";
 request2.ItemPage = "1";
 request2.ResponseGroup = new string[] { "OfferSummary" };

                
 // batch the two requests together
 ItemSearch itemSearch = new ItemSearch();
 itemSearch.Request = new ItemSearchRequest[] { request1,request2 };
 itemSearch.AWSAccessKeyId = accessKeyId;

 // issue the ItemSearch request
 ItemSearchResponse response = client.ItemSearch(itemSearch);


 foreach (var item in response.Items[0].Item)
 {
 
 }
 foreach (var item in response.Items[1].Item)
 {
 

 }

Is it possible to combine these two separate requests into one request and just have the first request return 2 items by setting keywords = "9120031340256 and 9120031340270"

Does anyone know how to do this?

Do I need to specifically search the UPC?

like image 741
Alex Gordon Avatar asked Dec 17 '25 20:12

Alex Gordon


2 Answers

From looking at the API docs I think you may want to use an ItemLookup if you want to get results for multiple UPCs.

ItemLookup itemLookup = new ItemLookup(){
    AssociateTag = "myaffiliatetag-20"
};
itemLookup.AWSAccessKeyId = MY_AWS_ID;

ItemLookupRequest itemLookupRequest = new ItemLookupRequest();
itemLookupRequest.IdTypeSpecified = true;
itemLookupRequest.IdType = ItemLookupRequestIdType.UPC;
itemLookupRequest.ItemId = new String[] { "9120031340300", "9120031340270" };
itemLookupRequest.ResponseGroup = new String[] { "OfferSummary" };
itemLookup.Request = new ItemLookupRequest[] { itemLookupRequest };

ItemLookupResponse response = client.ItemLookup(itemLookup);
foreach(var item in response.Items[0])
{
  //Do something...
  Console.WriteLine(item.ItemAttributes.Title);
}

That being said, if you are not working with lookups by some ID (UPC, ASIN, etc) your original code of doing batched keyword searches appears to be only way to make multiple keyword searches in a single request (that I could find..). If doing keyword searches you could always make a ItemSearchRequest generator method to cut down on duplicate code when creating multiples.

like image 165
bronsoja Avatar answered Dec 19 '25 10:12

bronsoja


You can use the following nuget package.

PM> Install-Package Nager.AmazonProductAdvertising

Example

var authentication = new AmazonAuthentication("accesskey", "secretkey");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.US);
var result = await client.GetItemsAsync(new string[] { "B00BYPW00I", "B004MKNBJG" });
like image 29
live2 Avatar answered Dec 19 '25 10:12

live2



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!