API地址
CA:https://developer.walmart.com/api/ca/mp/orders#operation/getAllOrders
US:https://developer.walmart.com/api/us/mp/orders#operation/getAllOrders
一、建立请求实体与响应实体类(CA和US站点相差不大)
请求实体
@Data
public class WmGetOrderRequest {
/**
* 请求的url
*/
private String url;
/**
* Get/Post
*/
private boolean isGet = true;
/**
* 下一个数据的链接,如果存在,则忽略继承类中填写的参数
*/
private String nextCursor;
/**
* sku
*/
private String sku;
/**
* 客户订单号
*/
private String customerOrderId;
/**
* 买家订单号
*/
private String purchaseOrderId;
/**
* 状态 Created, Acknowledged, Shipped, and Cancelled.
*/
private String status;
/**
* 订单创建开始日期
*/
private String createdStartDate;
/**
* 订单创建结束日期
*/
private String createdEndDate;
/**
* Limits orders returned to those that have orderLines with an expected ship date after this fromExpectedShipDate. Format: YYYY-MM-DD
*/
private String fromExpectedShipDate;
/**
* Limits orders returned to those that have orderLines with an expected ship date before this toExpectedShipDate. Format: YYYY-MM-DD
*/
private String toExpectedShipDate;
/**
* 最后一次更新开始日期
*/
private String lastModifiedStartDate;
/**
* 最后一次更新结束日期
*/
private String lastModifiedEndDate;
/**
* 分页数据大小,不得超过200
*/
private String limit;
/**
* Provides the image URL and product weight in response, if available. This parameter must be boolean, e.g.: productInfo=true.
*/
private String productInfo;
/**
* 订单类型,默认: "SellerFulfilled"
* SellerFulfilled(Default), WFSFulfilled and 3PLFulfilled.
*/
private String shipNodeType;
}
响应实体
public class GetAllOrderResponse {
private Meta meta;
private Elements elements;
}
public class Meta {
private Integer totalCount;
private Integer limit;
private String nextCursor;
}
public class Elements {
private List<Order> order;
}
public class Order {
private String purchaseOrderId;
private String customerOrderId;
private String customerEmailId;
private Date orderDate;
private ShippingInfo shippingInfo;
private OrderLines orderLines;
private ShipNode shipNode;
}
public class ShippingInfo {
private String phone;
private Date estimatedDeliveryDate;
private Date estimatedShipDate;
private String methodCode;
private PostalAddress postalAddress;
}
public class PostalAddress {
private String name;
private String address1;
private String address2;
private String city;
private String state;
private String postalCode;
private String country;
private String addressType;
}
public class OrderLines {
private List<OrderLine> orderLine;
}
public class OrderLine {
private String lineNumber;
private Item item;
private Charges charges;
private OrderLineQuantity orderLineQuantity;
private Date statusDate;
private OrderLineStatuses orderLineStatuses;
private Refund refund;
private Fulfillment fulfillment;
private String intentToCancel;
}
public class Item {
private String productName;
private String sku;
}
public class Charges {
private List<Charge> charge;
}
public class Charge {
private String chargeType;
private String chargeName;
private ChargeAmount chargeAmount;
private Tax tax;
}
public class ChargeAmount {
private String currency;
private Double amount;
}
public class Tax {
private String taxName;
private TaxAmount taxAmount;
}
public class TaxAmount {
private String currency;
private Double amount;
}
public class OrderLineQuantity {
private String unitOfMeasurement;
private Double amount;
}
public class OrderLineStatuses {
private List<OrderLineStatus> orderLineStatus;
}
public class OrderLineStatus {
private String status;
private StatusQuantity statusQuantity;
private String cancellationReason;
private String trackingInfo;
private String sellerOrderId;
}
public class StatusQuantity {
private String unitOfMeasurement;
private String amount;
}
public class Refund {
private String refundId;
private String refundComments;
private RefundCharges refundCharges;
}
public class RefundCharges {
private List<RefundCharge> refundCharge;
}
public class RefundCharge {
private String refundReason;
private Charge charge;
}
public class Fulfillment {
private String fulfillmentOption;
private String shipMethod;
private String storeId;
private String offerId;
private String pickUpDateTime;
private String pickUpBy;
}
public class ShipNode {
private String type;
private String name;
private String id;
}
一、CA获取订单,批量和单个
批量获取:
请求参数
我使用创建时间查询。
URL | https://marketplace.walmartapis.com/v3/ca/orders |
请求方式 | get请求 |
– | – |
参数 | 取值 |
createdStartDate | 时间格式为yyyy-MM-dd或者UTC时间格式 |
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(10, TimeUnit.SECONDS)//设置连接超时时间
.readTimeout(20, TimeUnit.SECONDS)//设置读取超时时间
.build();
Request request = new Request.Builder()
.addHeader("WM_CONSUMER.CHANNEL.TYPE", channelType)
.addHeader("WM_QOS.CORRELATION_ID", IdUtil.fastUUID())
.addHeader("WM_SVC.NAME", "walmart")
.addHeader("WM_CONSUMER.ID", consumerId)
.addHeader("Accept","application/json")
.addHeader("WM_SEC.TIMESTAMP", System.currentTimeMillis())
.addHeader("WM_SEC.AUTH_SIGNATURE", digitalSignature.getMwSecAuthSignature()
.url("https://marketplace.walmartapis.com/v3/ca/orders?createdStartDate='2024-08-14'")
.method("Get", null)
.build());
Response response = client.newCall(request).execute();
GetAllOrderResponse getAllOrderResponse = JSONObject.parseObject(response.body().string(), GetAllOrderResponse.class);
单个查询
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(10, TimeUnit.SECONDS)//设置连接超时时间
.readTimeout(20, TimeUnit.SECONDS)//设置读取超时时间
.build();
Request request = new Request.Builder()
.addHeader("WM_CONSUMER.CHANNEL.TYPE", channelType)
.addHeader("WM_QOS.CORRELATION_ID", IdUtil.fastUUID())
.addHeader("WM_SVC.NAME", "walmart")
.addHeader("WM_CONSUMER.ID", consumerId)
.addHeader("Accept","application/json")
.addHeader("WM_SEC.TIMESTAMP", System.currentTimeMillis())
.addHeader("WM_SEC.AUTH_SIGNATURE", digitalSignature.getMwSecAuthSignature())
.url("https://marketplace.walmartapis.com/v3/ca/orders/{purchaseOrderId}")
.method("Get", null)
.build();
Response response = client.newCall(request).execute();
Order order = JSONObject.parseObject(response.body().string(), Order.class);
二、US获取订单(批量和多个)
US建议使用更新时间
URL:https://marketplace.walmartapis.com/v3/orders
批量获取
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(10, TimeUnit.SECONDS)//设置连接超时时间
.readTimeout(20, TimeUnit.SECONDS)//设置读取超时时间
.build();
Request request = new Request.Builder()
.addHeader("WM_QOS.CORRELATION_ID", IdUtil.fastUUID())
.addHeader("WM_SVC.NAME", WALMART_KEY)
.addHeader("WM_SEC.ACCESS_TOKEN", token)
.addHeader("Authorization", Credentials.basic(clientId, clientSercet))
.addHeader("Accept", "application/json")
.url("https://marketplace.walmartapis.com/v3/orders?lastModifiedStartDate='2024-08-14'&lastModifiedEndDate='2024-08-14'")
.method("Get", null)
.build();
Response response = client.newCall(request).execute();
GetAllOrderResponse allOrderResponse = JSONObject.parseObject(response.body().string(), GetAllOrderResponse.class);
单个获取
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(10, TimeUnit.SECONDS)//设置连接超时时间
.readTimeout(20, TimeUnit.SECONDS)//设置读取超时时间
.build();
Request request = new Request.Builder()
.addHeader("WM_QOS.CORRELATION_ID", IdUtil.fastUUID())
.addHeader("WM_SVC.NAME", WALMART_KEY)
.addHeader("WM_SEC.ACCESS_TOKEN", token)
.addHeader("Authorization", Credentials.basic(clientId, clientSercet))
.addHeader("Accept", "application/json")
.url("https://marketplace.walmartapis.com/v3/orders/{purchaseOrderId}")
.method("Get", null)
.build();
Response response = client.newCall(request).execute();
Order order = JSONObject.parseObject(response.body().string(), Order.class);
总结
有几个注意点:
1.CA批量获取订单,只能获取状态为Created, Acknowledged, Shipped, and Cancelled,无法获取已完结的订单。
2.US批量获取订单,只能获取订单创建时间为最近180天的数据。能够获取已完结订单,Created, Acknowledged, Shipped, Delivered and Cancelled.
3.以上两种都是默认获取自发货订单(shipNodeType=SellerFulfilled)。CA的API没有区分类型,上面的方式需自己填充(SellerFulfilled)
4.US的WFS订单和正常订单获取方式一致,US增加参数shipNodeType=WFSFulfilled。CA需切换URL(https://marketplace.walmartapis.com/v3/ca/orders/wfs)