从亚马逊MWS检索订单的最佳方式是什么?
我目前的代码如下......
MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig();
config.ServiceURL = productsURL;
MarketplaceWebServiceOrders.MarketplaceWebServiceOrdersClient service = new MarketplaceWebServiceOrdersClient(appname, version, accesskeyID, secretkey, config);
ListOrdersRequest request = new ListOrdersRequest();
request.MarketplaceId = new MarketplaceIdList();
request.MarketplaceId.Id = new List<string>(new string[] { marketids[0] });
request.SellerId = merchantID;
request.OrderStatus = new OrderStatusList() { Status = new List<OrderStatusEnum>() { OrderStatusEnum.Unshipped, OrderStatusEnum.PartiallyShipped } };
request.CreatedAfter = Convert.ToDateTime(dc.Settings.SingleOrDefault().lastOrdersRetrieved);
ListOrdersResponse response = service.ListOrders(request);
我遇到了传递ISO日期的问题,如果您发现代码有任何其他问题,请随时告诉我。
答案 0 :(得分:1)
如果您在第二眼之后查找创建的内容,那么它就不会发现任何东西,就像亚马逊一样,您只能获取最后2分钟的订单数据。
我有一个问题,试图从现在设定时间 - 5分钟。在与亚马逊支持人员交谈后,他们提供了以下金块:“
在Orders API中,如果您未指定结束时间(CreatedBefore或 LastUpdatedBefore),它现在将假设(实际上,现在减去2 分钟)。在它的回复中,它会准确地告诉你它的时间 用作截止时间。“
在您的情况下,您需要删除CreatedAfter
请求并让亚马逊为您选择。
如果您正在寻找之后创建的,您可以获取亚马逊提供的响应时间并将其传递给您创建的后参数。
我现在列出订单的方法如下,请注意,这只是将订单列入控制台,但数据返回完全相同:
public List<string> ListOrders(MarketplaceWebServiceOrders.MarketplaceWebServiceOrders service, string merchantId, List<OrderStatusEnum> orderStatus)
{
List<string> salesOrderIds = new List<string>();
ListOrdersRequest listOrdersRequest = new ListOrdersRequest();
DateTime createdAfter = DateTime.Now.Add(new TimeSpan(-1, 0, 0));
DateTime createdbefore = DateTime.Now.Add(new TimeSpan(0, -15, 0));
listOrdersRequest.CreatedAfter = createdAfter;
listOrdersRequest.CreatedBefore = createdbefore;
listOrdersRequest.SellerId = merchantId;
listOrdersRequest.OrderStatus = new OrderStatusList();
foreach (OrderStatusEnum status in orderStatus)
{
listOrdersRequest.OrderStatus.Status.Add(status);
}
listOrdersRequest.FulfillmentChannel = new FulfillmentChannelList();
listOrdersRequest.FulfillmentChannel.Channel = new List<FulfillmentChannelEnum>();
listOrdersRequest.FulfillmentChannel.Channel.Add(FulfillmentChannelEnum.MFN);
listOrdersRequest.MarketplaceId = new MarketplaceIdList();
listOrdersRequest.MarketplaceId.Id = new List<string>();
listOrdersRequest.MarketplaceId.Id.Add("yourID");
ListOrdersResponse listOrdersResponse = service.ListOrders(listOrdersRequest);
int i = 0;
foreach (Order order in listOrdersResponse.ListOrdersResult.Orders.Order)
{
i++;
Console.WriteLine("Amazon Order ID: \t" + order.AmazonOrderId);
Console.WriteLine("Buyer Name: \t" + order.BuyerName);
Console.WriteLine("Buyer Email: \t" + order.BuyerEmail);
Console.WriteLine("Fulfillment Channel: \t" + order.FulfillmentChannel);
Console.WriteLine("Order Status: \t" + order.OrderStatus);
Console.WriteLine("Order Total: \t" + order.OrderTotal);
Console.WriteLine("Number of Items Shipped: \t" + order.NumberOfItemsShipped);
Console.WriteLine("Number of Items Unshipped: \t" + order.NumberOfItemsUnshipped);
Console.WriteLine("Purchase Date: \t" + order.PurchaseDate);
Console.WriteLine("===========================================================");
salesOrderIds.Add(order.AmazonOrderId);
}
Console.WriteLine("We returned a total of {0} records. ", i);
return salesOrderIds;
}