场景
最近要做货品部门的需求,涉及到发货和入库相关的API,对此研究了fulfillment-inbound-api
官方文档路径:fulfillment-inbound-api
从货品部门了解到的具体步骤为:
-
创建一个发货计划(createInboundShipmentPlan)
-
然后创建发货(createInboundShipment),
-
最后获取贴箱单(getLabels)
再了解到这些后我做了如下尝试
实操
准备工作
- 亚马逊店铺账号
- 开发者权限 如不会搭建开发者环境请点这里
- 配置AWS认证 如不会配置AWS认证请点这里,完成6以前的操作就可以调用sp-api了
第一、获取曾经发货的相关信息
1.先获取曾经创建过的发货-getShipments
String queryType="SHIPMENT";
String marketplaceId = "ATVPDKIKX0DER";
GetShipmentsResponse shipments = null;
List<String> shipmentStatusList = Arrays.asList("WORKING","SHIPPED","RECEIVING","CANCELLED","DELETED","CLOSED","ERROR","IN_TRANSIT","DELIVERED","CHECKED_IN");
ArrayList<String> shipmentIdList = new ArrayList<>();
try {
shipments = fbaInboundApi.getShipments(queryType,marketplaceId,shipmentStatusList,shipme ntIdList,start_time,end_time,null);
} catch (ApiException e) {
e.printStackTrace();
}
GetShipmentsResult payload = shipments.getPayload();
System.out.println("payload.getShipmentData() = " + payload.getShipmentData());
获取的结果如下:
2.获取曾经创建过发货的贴箱单-getLabels
注意:pageSize=5是事先向货品询问好某个shipmentId本次发货一共五个贴箱单。
GetLabelsResponse labels = null;
try {
labels = fbaInboundApi.getLabels("shipmentId", "PackageLabel_Letter_2", "BARCODE_2D", null, null, null, 5, null);
} catch (ApiException e) {
e.printStackTrace();
}
System.out.println("DownloadURL = " + labels.getPayload().getDownloadURL());
获取的结果如下:
在有了第一步获取的信息之后,打算着手研究整套流程。
第二、完整流程
createInboundShipmentPlan–>createInboundShipment–>getLabels
Java创建-createInboundShipmentPlan
CreateInboundShipmentPlanRequest body = new CreateInboundShipmentPlanRequest();
Address address = new Address();
address.setName("your shop");
address.setAddressLine1("your address");
address.setDistrictOrCounty("your districtOrCounty");
address.setCity("your city");
address.setStateOrProvinceCode("your stateOrProvinceCode");
address.setCountryCode("your countryCode");
address.setPostalCode("your postalCode");
body.setShipFromAddress(address);
body.setLabelPrepPreference(LabelPrepPreference.SELLER_LABEL);
body.setShipToCountryCode("US");
body.setShipToCountrySubdivisionCode("US-CA");
InboundShipmentPlanRequestItemList list = new InboundShipmentPlanRequestItemList();
InboundShipmentPlanRequestItem inboundShipmentPlanRequestItem = new InboundShipmentPlanRequestItem();
inboundShipmentPlanRequestItem.setASIN("your asin");
inboundShipmentPlanRequestItem.setSellerSKU("your seller sku");
inboundShipmentPlanRequestItem.setCondition(Condition.NEWITEM);
inboundShipmentPlanRequestItem.setQuantity(1);
inboundShipmentPlanRequestItem.setQuantityInCase(1);
PrepDetailsList prepDetails = new PrepDetailsList();
PrepDetails details = new PrepDetails();
details.setPrepInstruction(PrepInstruction.LABELING);
details.setPrepOwner(PrepOwner.SELLER);
prepDetails.add(details);
inboundShipmentPlanRequestItem.setPrepDetailsList(prepDetails);
list.add(inboundShipmentPlanRequestItem);
body.setInboundShipmentPlanRequestItems(list);
CreateInboundShipmentPlanResponse shipmentPlan = null;
System.out.println("body = " + body);
try {
shipmentPlan = fbaInboundApi.createInboundShipmentPlan(body);
} catch (ApiException e) {
e.printStackTrace();
} finally {
System.out.println("shipmentPlan.getErrors() = " + shipmentPlan.getErrors());System.out.println("shipmentPlan.getPayload() = " + shipmentPlan.getPayload());
}
发起请求之后报错400,请求未通过。
注:在仔细检查完参数之后再次尝试还是失败,转战python之后相同的参数发送请求成功。由于笔者水平有限,一时没法解决这个问题。通过python最终获取到的贴箱单如下: