亚马逊产品广告API-搜索多个UPC

本文关键字:搜索 UPC API- 亚马逊 | 更新日期: 2023-09-27 18:00:10

使用亚马逊产品广告API,我正在搜索两个不同的UPC:

 // 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)
 {
 
 }

是否可以将这两个单独的请求合并为一个请求,并通过设置keywords = "9120031340256 and 9120031340270" 使第一个请求返回2项

有人知道怎么做吗?

我需要专门搜索UPC吗?

亚马逊产品广告API-搜索多个UPC

通过查看API文档,我认为如果您想获得多个UPC的结果,您可能需要使用ItemLookup。

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);
}

也就是说,如果不使用某些ID(UPC、ASIN等)进行查找,那么进行批量关键字搜索的原始代码似乎是在单个请求中进行多个关键字搜索的唯一方法(我可以找到..)。如果进行关键字搜索,您可以始终使用ItemSearchRequest生成器方法来减少创建多个关键字时的重复代码。

您可以使用以下nuget包裹

PM> Install-Package Nager.AmazonProductAdvertising

示例

var authentication = new AmazonAuthentication("accesskey", "secretkey");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.US);
var result = await client.GetItemsAsync(new string[] { "B00BYPW00I", "B004MKNBJG" });