Amazon-SP-API-CSharp
Amazon-SP-API-CSharp copied to clipboard
Issues with Commit - be3f52e951d8dc515bf12e2035cd0e42a5c5b893 - InventoryDetails, CatalogItemServicesa and OrderServices updated
Hello,
I found an issue and tracked it back to commit InventoryDetails, CatalogItemServicesa and OrderServices updated..
There is a duplicate method of GetOrdersAsync was created that took a single argument that was the same as the previous/older GetOrdersAsync method. It left out some code around getting PII data from the other method. In my code I was calling the method with a single parameter (ParameterOrderList) and before it called the older method and would properly get the PII data. Though with the new method it would error out on Amazon's side because I was requesting PII without the other parameter info that the older method provided. I worked around it by providing null on the second parameter so it would forcibly call the older method. Can this new GetOrdersAsync just be removed? I am unsure what it is doing differently from the old except for not providing the functionality the old method provided. I will provide code snippets of the two methods so you can see the differences. Thanks.
OLD:
public async Task<OrderList> GetOrdersAsync(ParameterOrderList searchOrderList, CancellationToken cancellationToken = default(CancellationToken))
{
new OrderList();
if (searchOrderList.MarketplaceIds == null || searchOrderList.MarketplaceIds.Count == 0)
{
searchOrderList.MarketplaceIds = new List<string>();
searchOrderList.MarketplaceIds.Add(base.AmazonCredential.MarketPlace.ID);
}
if (searchOrderList.IsNeedRestrictedDataToken && searchOrderList.RestrictedDataTokenRequest == null)
{
RestrictedResource restrictedResource = new RestrictedResource();
restrictedResource.method = FikaAmazonAPI.AmazonSpApiSDK.Models.Token.Method.GET.ToString();
restrictedResource.path = OrdersApiUrls.Orders;
restrictedResource.dataElements = new List<string> { "buyerInfo", "shippingAddress" };
CreateRestrictedDataTokenRequest restrictedDataTokenRequest = new CreateRestrictedDataTokenRequest
{
restrictedResources = new List<RestrictedResource> { restrictedResource }
};
searchOrderList.RestrictedDataTokenRequest = restrictedDataTokenRequest;
}
List<KeyValuePair<string, string>> parameters = searchOrderList.getParameters();
await CreateAuthorizedRequestAsync(OrdersApiUrls.Orders, RestSharp.Method.Get, parameters, null, CacheTokenData.TokenDataType.Normal, searchOrderList, cancellationToken);
GetOrdersResponse getOrdersResponse = await ExecuteRequestAsync<GetOrdersResponse>(RateLimitType.Order_GetOrders, cancellationToken);
string nextToken = getOrdersResponse.Payload.NextToken;
OrderList orderList = getOrdersResponse.Payload.Orders;
if (!string.IsNullOrWhiteSpace(getOrdersResponse.Payload.LastUpdatedBefore))
{
orderList.LastUpdatedBefore = DateTime.Parse(getOrdersResponse.Payload.LastUpdatedBefore);
}
int PageCount = 1;
if (searchOrderList.MaxNumberOfPages.HasValue && searchOrderList.MaxNumberOfPages.Value == 1)
{
orderList.NextToken = nextToken;
}
else
{
while (!string.IsNullOrEmpty(nextToken))
{
OrdersList ordersList = await GetGetOrdersByNextTokenAsync(nextToken, searchOrderList, cancellationToken);
orderList.AddRange(ordersList.Orders);
nextToken = ordersList.NextToken;
if (searchOrderList.MaxNumberOfPages.HasValue)
{
PageCount++;
if (PageCount >= searchOrderList.MaxNumberOfPages.Value)
{
break;
}
}
}
}
return orderList;
}
NEW:
public async Task<OrderList> GetOrdersAsync(ParameterOrderList searchOrderList)
{
new OrderList();
if (searchOrderList.MarketplaceIds == null || searchOrderList.MarketplaceIds.Count == 0)
{
searchOrderList.MarketplaceIds = new List<string>();
searchOrderList.MarketplaceIds.Add(base.AmazonCredential.MarketPlace.ID);
}
List<KeyValuePair<string, string>> parameters = searchOrderList.getParameters();
await CreateAuthorizedRequestAsync(OrdersApiUrls.Orders, RestSharp.Method.Get, parameters, null, CacheTokenData.TokenDataType.Normal, searchOrderList);
GetOrdersResponse obj = await ExecuteRequestAsync<GetOrdersResponse>(RateLimitType.Order_GetOrders);
string nextToken = obj.Payload.NextToken;
OrderList orders = obj.Payload.Orders;
int num = 1;
if (searchOrderList.MaxNumberOfPages.HasValue && searchOrderList.MaxNumberOfPages.Value == 1)
{
orders.NextToken = nextToken;
}
else
{
while (!string.IsNullOrEmpty(nextToken))
{
OrdersList getOrdersByNextToken = GetGetOrdersByNextToken(nextToken, searchOrderList);
orders.AddRange(getOrdersByNextToken.Orders);
nextToken = getOrdersByNextToken.NextToken;
if (searchOrderList.MaxNumberOfPages.HasValue)
{
num++;
if (num >= searchOrderList.MaxNumberOfPages.Value)
{
break;
}
}
}
}
return orders;
}