Amazon Product Advertising API - searching for multiple UPCs - c#

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?

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.

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

Related

How to change column height in Google sheets C#

I'm trying to modify the row height in Google sheets of a row I just added. The row consists of a list of strings (i.e. cells). First I add the row, then I try to modify the height:
// I need to convert my list of strings into a list of objects
// there's probably a better way to do this...
var valueRange = new ValueRange();
var oblist = new List<object>();
foreach (var thing in columns)
{
oblist.Add(thing);
}
valueRange.Values = new List<IList<object>>() { oblist };
var appendRequest = service.Spreadsheets.Values.Update(valueRange, spreadsheetId, $"{sheetname}!A{rownumber}:Z{rownumber}");
appendRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
var appendResponse = appendRequest.Execute();
// now change the row height to 100 pixels.
BatchUpdateSpreadsheetRequest r = new BatchUpdateSpreadsheetRequest();
UpdateDimensionPropertiesRequest request = new UpdateDimensionPropertiesRequest());
request.Range = new DimensionRange();
request.Range.SheetId = sheetId;
request.Range.Dimension = "ROWS";
request.Range.StartIndex =
request.Range.EndIndex = rownumber;
request.Properties = new DimensionProperties();
request.Properties.PixelSize = 100;
request.Fields = "pixelSize";
r.Requests.Add(request);
var bu = service.Spreadsheets.BatchUpdate(r, spreadsheetId);
bu.Execute();
The problem is in the third-last line where I can't add request to the Requests list, as request is not derived from the Request class.
Instead of trying to add the request directly to the batch, I need to add a Requests list to the batch, and then add the request to the Requests list:
UpdateDimensionPropertiesRequest request = new UpdateDimensionPropertiesRequest();
request.Range = new DimensionRange();
request.Range.SheetId = sheetId;
request.Range.Dimension = "ROWS";
request.Range.StartIndex = firstrow;
request.Properties = new DimensionProperties();
request.Properties.PixelSize = 100;
request.Fields = "pixelSize";
// now add the request to the batch
BatchUpdateSpreadsheetRequest busr = new BatchUpdateSpreadsheetRequest();
busr.Requests = new List<Request>();
busr.Requests.Add(new Request { UpdateDimensionProperties = request });
var bur = service.Spreadsheets.BatchUpdate(busr, spreadsheetId);
bur.Execute();

VSTS REST API for C# - How to get ALL (not first 250) pull requests that merge a commit Id?

I am using the below API and method to try and get all PR commits that merge a given commitId. But the API only returns a max of 250. Is there a parameter or pagination technique to get the remaining?
public void GetAllPullRequestsForCommit(Guid repoId, string commitId)
{
var query = new GitPullRequestQuery();
var input = new GitPullRequestQueryInput() { Type = GitPullRequestQueryType.Commit, Items = new List<string>() { commitId } };
query.QueryInputs = new List<GitPullRequestQueryInput>() { input };
var response = _gitClient.GetPullRequestQueryAsync(query, repoId).Result;
}

Rally .NET: Query for project admins that belong to a specific project?

I am looking for a List object that is populated with project admins for a specific project that is within a specific workspace.
Would like some sample code that can query the API for to retrieve all the project admins email addresses.
Here is some sample code I have tried.
public void getProjectAdmins(string workspaceRef, string projectRef)
{
this.EnsureRallyIsAuthenticated();
Request projectAdminRequest = new Request("User");
projectAdminRequest.Workspace = workspaceRef;
projectAdminRequest.Project = projectRef;
projectAdminRequest.ProjectScopeUp = RallyConstant.ProjectScopeUp;
projectAdminRequest.ProjectScopeDown = RallyConstant.ProjectScopeDown;
projectAdminRequest.Fetch = new List<string>()
{
"Admin", "Email"
};
try
{
//query the items in the list
projectAdminRequest.Query = new Query();
QueryResult result = _rallyRestApi.Query(projectAdminRequest);
//iterate through the result set
foreach (var admin in result.Results)
{
var adminResult = admin[RallyConstant.Owner];
if (adminResult != null)
{
var x = adminResult[RallyQueryConstant.ReferenceObject];
}
}
}
catch (WebException)
{
Console.WriteLine(RallyQueryConstant.WebExceptionMessage);
}
}
You should be able to query the ProjectPermission endpoint filtered to your project in question like so:
Request projectAdminRequest = new Request("ProjectPermission");
projectAdminRequest.Workspace = workspaceRef;
projectAdminRequest.Fetch = new List<string>() {"User", "EmailAddress"};
projectAdminRequest.Query = Query.And(
new Query("Project", Query.Operator.Equals, "/project/12345"),
new Query("Role", Query.Operator.Equals, "Project Admin"));
Fetching User and EmailAddress should include the data you're looking for in your request.

How to get all post/activity from google plus using c#

I am trying to get all the posts from google+ wall but I am able to get only 20 post. Kindly help me. My code is-
PlusService plus = new PlusService(
new Google.Apis.Services.BaseClientService.Initializer()
{
ApiKey = "AIzaSyDWG1Ho6PVC6FlPXv5rommyzCAf0ziHkTo"
});
ActivitiesResource ar = new ActivitiesResource(plus);
ActivitiesResource.ListRequest list = ar.List(id, new ActivitiesResource.ListRequest.CollectionEnum());
ActivityFeed feed = list.Execute();
Use the MaxResults property of the ListRequest class.
PlusService plus = new PlusService(
new Google.Apis.Services.BaseClientService.Initializer()
{
ApiKey = "AIzaSyDWG1Ho6PVC6FlPXv5rommyzCAf0ziHkTo"
});
ActivitiesResource ar = new ActivitiesResource(plus);
ActivitiesResource.ListRequest list = ar.List(id, new ActivitiesResource.ListRequest.CollectionEnum());
list.MaxResults = 100; // Or whatever number you want
ActivityFeed feed = list.Execute();
Note that the maximum number is 100.
Google.Apis.Orkut.v2.ActivitiesResource.ListRequest Class Reference

Amazon MWS C# Products GetCompetitivePricingForSKU throws Exception

When I'm trying to Request the Competettive Price for a Product i always get a
MarketplaceWebServiceProductsException
The Message is empty, and the TargetSite gives me
T Call[T](MWSClientCsRuntime.IMwsRequestType1[T], MWSClientCsRuntime.IMwsObject)
Here is the Code I'm running
MarketplaceWebServiceProducts.MarketplaceWebServiceProducts service = new MarketplaceWebServiceProductsClient (config.MWS_AccessKeyId, config.MWS_secretKey);
SellerSKUListType list = new SellerSKUListType ();
List<String> SKUList = new List<String> ();
SKUList.Add (SKU);
list.SellerSKU = SKUList;
GetCompetitivePricingForSKURequest request = new GetCompetitivePricingForSKURequest ();
request.MarketplaceId = config.MWS_MarketPlaceId;
request.SellerId = config.MWS_SellerId;
request.SellerSKUList = list;
GetCompetitivePricingForSKUResponse response = service.GetCompetitivePricingForSKU (request);
Have you tried to specify application name and application version?
var config = new MarketplaceWebServiceProductsConfig();
config.ServiceURL = "https://mws.amazonservices.com/Products/2011-10-01";
config.SetUserAgent(ApplicationName, ApplicationVersion);
var service = new MarketplaceWebServiceProductsClient(ApplicationName, ApplicationVersion, MWSaccessKey, MWSsecretKey, config);

Categories