网址相关
API接口文档:https://developer.wayfair.com/docs/cn/
后台登录地址:https://partners.wayfair.com/v/developer/login/index
一、创建应用
1.登录Wayfair后台
2.保存之后会出现Client Id和Client Secret
二、获取Token
生产/沙箱URL同一个:https://sso.auth.wayfair.com/oauth/token
接口请求为POST,参数:
参数名 | 取值 |
---|---|
client_id | 你的client_id |
client_secret | 你的client_secret |
audience | 沙箱使用:https://sandbox.api.wayfair.com/,生产使用:https://api.wayfair.com/ |
grant_type | client_credentials |
使用示例:
public String getToken(String apiUrl, String body) throws Exception {
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody requestBody = RequestBody.create(mediaType, body);
Headers.Builder headerBuilder = new Headers.Builder();
headerBuilder.add("Accept", "application/json");
headerBuilder.add("Content-type", "application/json");
Request request= new Request.Builder()
.url("https://sso.auth.wayfair.com/oauth/token")
.method("POST", requestBody)
.headers(headerBuilder.build())
.build();
Response response = null;
try {
response = client.newCall(request).execute();
int code = response.code();
if (code == 200 || code == 201) {
return response.body().string();
}else{
throw new Exception("异常处理");
}
}finally {
if (response != null) {
response.close();
}
}
}
响应示例:
{
"access_token":"eyJ0eXAiOiJKV1Qi...X1rNJFNVGBwmFQ5tepKwno7DEIjDg",
"expires_in":43200,
"scope":"read:inventory write:inventory",
"token_type":"Bearer"
}
三.获取订单,按时间范围获取
DropShip Order Query 直接发货订单查询。
参数结构比较特殊,建议使用org.mountcloud.graphql.request.query包下的DefaultGraphqlQuery类。
需要在域名后面拼接v1/graphql/
请求参数:
使用示例:
public void getOrders(String token) throws Exception {
DefaultGraphqlQuery query = new DefaultGraphqlQuery("getDropshipPurchaseOrders");
query.addParameter("fromDate", "开始时间").addParameter("limit", 1000);
query.addResultAttributes(
"poNumber",
"poDate",
"orderId",
"estimatedShipDate",
"customerName",
"customerAddress1",
"customerAddress2",
"customerCity",
"customerState",
"customerPostalCode",
"orderType",
"packingSlipUrl"
);
ResultAttributtes shippingInfo = new ResultAttributtes("shippingInfo");
shippingInfo.addResultAttributes("shipSpeed", "carrierCode");
ResultAttributtes warehouse = new ResultAttributtes("warehouse");
warehouse.addResultAttributes("id", "name");
ResultAttributtes address = new ResultAttributtes("address");
address.addResultAttributes("name", "address1", "address2", "address3", "city", "state", "country", "postalCode");
warehouse.addResultAttributes(address);
ResultAttributtes products = new ResultAttributtes("products");
products.addResultAttributes("partNumber", "quantity", "price");
ResultAttributtes shipTo = new ResultAttributtes("shipTo");
shipTo.addResultAttributes("name", "address1", "address2", "address3", "city", "state", "country", "postalCode", "phoneNumber");
query.addResultAttributes(shippingInfo);
query.addResultAttributes(warehouse);
query.addResultAttributes(products);
query.addResultAttributes(shipTo);
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody requestBody = RequestBody.create(mediaType, query.toString());
Headers.Builder headerBuilder = new Headers.Builder();
headerBuilder.add("Accept", "application/json");
headerBuilder.add("Content-type", "application/json");
Request request= new Request.Builder()
.url("https://sso.auth.wayfair.com/oauth/token")
.method("POST", requestBody)
.headers(headerBuilder.build())
.build();
Response response = null;
try {
response = client.newCall(request).execute();
int code = response.code();
if (code == 200 || code == 201) {
String result = response.body().string();
}else{
throw new Exception("异常处理");
}
}finally {
if (response != null) {
response.close();
}
}
}
响应示例:
响应结构与请求参数结构一致。但是是数组结构。
总结
Wayfair拉取的直接发货订单是没有订单状态的。