Endpoint and authentication
この chain の request は同一 endpoint。headers は setup により異なる — tab を選択。
URL:
https://api.zonos.com/graphql
Headers:
自社 Verified Account 下で自社 order を ship。自身として authenticate — account key 不要。
credentialToken: {{YOUR_API_TOKEN}}
確認場所: Zonos Dashboard → Settings → Integrations → Account Key section。API key row token が credentialToken。
Example request
copy-and-adapt 可能な complete CreateDeclarationShipment request — mutation、variables、response — 米国 DDP 向け単一 Japan Post parcel 用。各 input は以下 step-by-step で breakdown。
mutation CreateDeclarationShipment($partyInput: [PartyCreateWorkflowInput!]!$itemInput: [ItemCreateWorkflowInput!]!$cartonInput: [CartonCreateWorkflowInput!]!$shipmentRatingInput: ShipmentRatingCreateWorkflowInput!$landedCostInput: LandedCostWorkFlowInput!$shipmentInput: ShipmentCreateWorkflowInput!) { partyCreateWorkflow(input: $partyInput) { id type location { line1 locality postalCode countryCode } } itemCreateWorkflow(input: $itemInput) { id name sku amount currencyCode hsCode } cartonsCreateWorkflow(input: $cartonInput) { id length width height dimensionalUnit weight weightUnit } shipmentRatingCreateWorkflow(input: $shipmentRatingInput) { id amount } landedCostCalculateWorkflow(input: $landedCostInput) { id method currencyCode amountSubtotals { duties taxes fees shipping landedCostTotal } } shipmentCreateWorkflow(input: $shipmentInput) { id trackingDetails { number } shipmentCartons { label { url } } }}Step-by-step
以下 table の Status column 用語:
- Required — なければ request fail。
- Required for label — GraphQL schema では optional だが valid Japan Post 米国 label に必要。
- Conditional — 他 field に依存(inline 記載)。
- Recommended — optional だが accurate duty/tax に重要。
- Optional — 不要。
1. partyCreateWorkflow
shipment の parties を create — 最低 ORIGIN(ship from)と DESTINATION(buyer / consignee)。
| Field↕ | Status↕ | Notes↕ |
|---|---|---|
type | Required | ORIGIN, DESTINATION, RETURN, etc. |
location.countryCode | Required | ISO-2 country code. |
location.line1, locality, administrativeAreaCode, postalCode | Required for label | valid label に必要な address fields。 |
person.firstName, lastName, phone | Required for label | valid label に必要な contact details。 |
person.companyName, email | Optional |
Example payload:
[
{ "type": "DESTINATION", "location": { "countryCode": "US" }, "person": {} },
{ "type": "ORIGIN", "location": { "countryCode": "JP" }, "person": {} }
]
response は created Party ID と resolved address fields を return。
2. itemCreateWorkflow
shipment を構成する line items を create。commercial invoice に表示され landed-cost calculation を drive する SKU。
| Field↕ | Status↕ | Notes↕ |
|---|---|---|
currencyCode | Required | Currency of the unit price. |
quantity | Required | Number of units of this item. |
amount | Conditional | unit price(total ではない)。totalAmount 未指定時 required。 |
totalAmount | Optional | amount の代替; amount は totalAmount / quantity から derive。 |
hsCode | Recommended | Harmonized System tariff code。duty rates を drive。 |
countryOfOrigin | Recommended | item 製造国 ISO-2 code。duty / FTA を drive。 |
name, description | Recommended | customer-facing product name + description。 |
customsDescription | Optional | customs description override。 |
sku, productId | Optional | internal identifiers。 |
measurements | Optional | per-unit weight / dimensions。 |
HS code、country of origin、amount が step 5 duty/tax outcome に最も影響する 3 field。
3. cartonsCreateWorkflow
physical packages — item を入れる boxes、polybags、letters を create。
| Field↕ | Status↕ | Notes↕ |
|---|---|---|
dimensionalUnit | Required | INCH or CENTIMETER. |
weight, weightUnit | Required for label | Japan Post は package weight 必須。 |
length, width, height | Optional | outer dimensions。 |
type | Optional | packaging style(box、polybag、letter)。default PACKAGE。 |
各 carton は step 6 carrier label 上 1 parcel。multiple cartons → carton ごと tracking number の multi-piece shipment。
4. shipmentRatingCreateWorkflow
buyer に請求する shipping rate quote を record。
| Field↕ | Status↕ | Notes↕ |
|---|---|---|
amount | Required | buyer の shipping 支払額。free なら 0。 |
currencyCode | Required | Currency of amount. |
serviceLevelCode | Required | carrier service code(例: japan_post.air.parcel)。 |
displayName | Optional | receipt / invoice 用 display name。 |
checkout で buyer に quote された rate。landed-cost calculation の „shipping“ subtotal となり correct CIF value で duty/tax を compute。
5. landedCostCalculateWorkflow
destination country 向け duties、taxes、fees calculation を実行。prior steps の items、parties、shipping cost を使用。
| Field↕ | Status↕ | Notes↕ |
|---|---|---|
endUse | Required | NOT_FOR_RESALE または FOR_RESALE。destination により commercial vs personal end use で異なる rates。 |
tariffRate | Required | 省略時 ZONOS_PREFERRED。Zonos に適用 tariff source/methodology を指示。 |
calculationMethod | Recommended | DDP(buyer prepay)または DDU(door で pay)。prepaid は DDP。LandedCost.amountSubtotals に duty/tax 含むか drive。 |
currencyCode | Optional | landed-cost subtotals return currency。 |
arrivalDate | Optional | 指定時 FX rates と tariff schedules をこの date に pin。 |
response に amountSubtotals(duties、taxes、fees、shipping、landedCostTotal)— checkout で buyer に表示し commercial invoice に print する数値。
6. shipmentCreateWorkflow
terminal step — Shipment entity を create、carrier label を generate、(optional)commercial invoice / packing slip。
Japan Post Verified Account では Zonos が Japan Post Label API(code 52)を呼び出し Later Pay Numbers を inject、Declaration ID を create し Japan Post return tracking number に link する step。
Key fields:
| Field↕ | Status↕ | Notes↕ |
|---|---|---|
serviceLevel | Required for label | ship する Japan Post service(例: japan_post.air.ems_merchandise)。japan_post.* service level 必須。 |
generateLabel | Optional | default true; label return には true 必須。 |
contentsType | Recommended | SALE_OF_GOODS、GIFT、DOCUMENTS、SAMPLE 等。customs treatment を drive。 |
nonDelivery | Optional | delivery fail 時 carrier action: RETURN、ABANDON、FORWARD。 |
references | Optional | label と commercial invoice に print する merchant-supplied reference numbers。以下参照。 |
declaredValue / isDeclaredValue | Optional | shipment insurance value。 |
shipmentConsolidationId | Optional | batch dispatch の一部の場合に使用。 |
references sub-input
carrier label および/または commercial invoice に print。consignee または customs authority が見る PO number、license number、free-text remarks を surface。
| Field↕ | Status↕ | Notes↕ | Length↕ |
|---|---|---|---|
invoiceNumber | Optional | merchant invoice number。 | — |
purchaseOrderNumber | Optional | merchant PO number。 | — |
licenseNumber | Optional | export/import license number。 | — |
certificateNumber | Optional | customs certificate number。 | — |
paymentConditions | Optional | commercial invoice 表示 free-text terms-of-payment。 | 200 characters 以内 — 超過は printed invoice overflow。 |
customsRemarks | Optional | free-text customs remarks。 | — |
taxCode | Optional | label に print する custom tax code。 | — |
Response
return された Shipment の主要 fields:
{
id
trackingDetails {
number
}
shipmentCartons {
label {
url
labelImage
}
}
}
trackingDetails.number は Japan Post tracking number。
label object は 2 方式で label return — workflow に合う方(または両方)を request:
| Field↕ | Returns↕ | Use when↕ |
|---|---|---|
url | rendered label file(PDF)の hosted link。download/print 可能。 | link を hand off — open、email、または payload なしで後 fetch。 |
labelImage | response inline base64 label image(PNG/PDF/ZPL)。 | fulfillment workflow attach または WMS save 用に label bytes を response で直接取得。 |
必要 field のみ select。url は response を small に; labelImage は full label inline で 2nd round trip 不要。上記 example は url を request。
Error handling
- Validation errors(required field 欠如、invalid country code 等)は standard GraphQL
errorsarray で return し chain 残り abort。 - Japan Post errors(label generation failure、invalid address 等)は
shipmentCreateWorkflow上 GraphQL error。retry 必要なら support 連絡 — recommended は corrected input で full mutation resubmit。
Permissions
各 step は independently secured。API key に chain 各 entity write scope 必須(ITEM_WRITE、CARTON_WRITE、SHIPMENT_RATING_WRITE、LANDED_COST_WRITE、SHIPMENT_WRITE)。Verified Account standard merchant role がすべて grant。
Next steps
- Batch dispatch (consolidation) — 1 日分 parcel を 1 つの Japan Post deferred-payment dispatch slip に bundle。
単一 shipment の作成
CreateDeclarationShipmentGraphQL workflow は Japan Post shipment を raw inputs から printable label まで 1 round trip で処理。CreateDeclarationShipmentは 6 つの*Workflowmutation を 1 GraphQL request に chain。各 step は前 step の data を build し、complete shipment を 1 round trip で create:Workflowmutation は chained 設計 — step 間で ID を thread 不要、step ごと separate request 不要。document 全体 submit で finalShipmentを取得。final step の
serviceLevelが Japan Post service level(japan_post.*)の場合、Zonos は Verified Account Later Pay Numbers で Japan Post Label API(code 52)を呼び出し、label と tracking number を generate、Declaration ID を create して link — すべて finalshipmentCreateWorkflowstep 内。