DOCS

単一 shipment の作成

単一 shipment の作成

CreateDeclarationShipment GraphQL workflow は Japan Post shipment を raw inputs から printable label まで 1 round trip で処理。

CreateDeclarationShipment は 6 つの *Workflow mutation を 1 GraphQL request に chain。各 step は前 step の data を build し、complete shipment を 1 round trip で create:

partyCreateWorkflow            → describe origin + destination parties
itemCreateWorkflow             → describe the line items
cartonsCreateWorkflow          → describe the physical packaging
shipmentRatingCreateWorkflow   → record the carrier rate quote
landedCostCalculateWorkflow    → calculate duties / taxes / fees
shipmentCreateWorkflow         → create the shipment + label

Workflow mutation は chained 設計 — step 間で ID を thread 不要、step ごと separate request 不要。document 全体 submit で final Shipment を取得。

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 — すべて final shipmentCreateWorkflow step 内。

1 mutation の理由: 各 step は前 step に依存(landed cost は items + parties 必要、label はすべて必要)。1 GraphQL document に bundle して data consistency を保ち 5 extra round trip を回避。

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 → SettingsIntegrationsAccount 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。

1mutation CreateDeclarationShipment(
2$partyInput: [PartyCreateWorkflowInput!]!
3$itemInput: [ItemCreateWorkflowInput!]!
4$cartonInput: [CartonCreateWorkflowInput!]!
5$shipmentRatingInput: ShipmentRatingCreateWorkflowInput!
6$landedCostInput: LandedCostWorkFlowInput!
7$shipmentInput: ShipmentCreateWorkflowInput!
8) {
9 partyCreateWorkflow(input: $partyInput) {
10 id
11 type
12 location {
13 line1
14 locality
15 postalCode
16 countryCode
17 }
18 }
19 itemCreateWorkflow(input: $itemInput) {
20 id
21 name
22 sku
23 amount
24 currencyCode
25 hsCode
26 }
27 cartonsCreateWorkflow(input: $cartonInput) {
28 id
29 length
30 width
31 height
32 dimensionalUnit
33 weight
34 weightUnit
35 }
36 shipmentRatingCreateWorkflow(input: $shipmentRatingInput) {
37 id
38 amount
39 }
40 landedCostCalculateWorkflow(input: $landedCostInput) {
41 id
42 method
43 currencyCode
44 amountSubtotals {
45 duties
46 taxes
47 fees
48 shipping
49 landedCostTotal
50 }
51 }
52 shipmentCreateWorkflow(input: $shipmentInput) {
53 id
54 trackingDetails {
55 number
56 }
57 shipmentCartons {
58 label {
59 url
60 }
61 }
62 }
63}

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)。

FieldStatusNotes
typeRequiredORIGIN, DESTINATION, RETURN, etc.
location.countryCodeRequiredISO-2 country code.
location.line1, locality, administrativeAreaCode, postalCodeRequired for labelvalid label に必要な address fields。
person.firstName, lastName, phoneRequired for labelvalid label に必要な contact details。
person.companyName, emailOptional

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。

FieldStatusNotes
currencyCodeRequiredCurrency of the unit price.
quantityRequiredNumber of units of this item.
amountConditionalunit price(total ではない)。totalAmount 未指定時 required。
totalAmountOptionalamount の代替; amounttotalAmount / quantity から derive。
hsCodeRecommendedHarmonized System tariff code。duty rates を drive。
countryOfOriginRecommendeditem 製造国 ISO-2 code。duty / FTA を drive。
name, descriptionRecommendedcustomer-facing product name + description。
customsDescriptionOptionalcustoms description override。
sku, productIdOptionalinternal identifiers。
measurementsOptionalper-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。

FieldStatusNotes
dimensionalUnitRequiredINCH or CENTIMETER.
weight, weightUnitRequired for labelJapan Post は package weight 必須。
length, width, heightOptionalouter dimensions。
typeOptionalpackaging 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。

FieldStatusNotes
amountRequiredbuyer の shipping 支払額。free なら 0
currencyCodeRequiredCurrency of amount.
serviceLevelCodeRequiredcarrier service code(例: japan_post.air.parcel)。
displayNameOptionalreceipt / 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 を使用。

FieldStatusNotes
endUseRequiredNOT_FOR_RESALE または FOR_RESALE。destination により commercial vs personal end use で異なる rates。
tariffRateRequired省略時 ZONOS_PREFERRED。Zonos に適用 tariff source/methodology を指示。
calculationMethodRecommendedDDP(buyer prepay)または DDU(door で pay)。prepaid は DDPLandedCost.amountSubtotals に duty/tax 含むか drive。
currencyCodeOptionallanded-cost subtotals return currency。
arrivalDateOptional指定時 FX rates と tariff schedules をこの date に pin。

response に amountSubtotalsdutiestaxesfeesshippinglandedCostTotal)— 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:

FieldStatusNotes
serviceLevelRequired for labelship する Japan Post service(例: japan_post.air.ems_merchandise)。japan_post.* service level 必須。
generateLabelOptionaldefault true; label return には true 必須。
contentsTypeRecommendedSALE_OF_GOODSGIFTDOCUMENTSSAMPLE 等。customs treatment を drive。
nonDeliveryOptionaldelivery fail 時 carrier action: RETURNABANDONFORWARD
referencesOptionallabel と commercial invoice に print する merchant-supplied reference numbers。以下参照。
declaredValue / isDeclaredValueOptionalshipment insurance value。
shipmentConsolidationIdOptionalbatch dispatch の一部の場合に使用。

references sub-input

carrier label および/または commercial invoice に print。consignee または customs authority が見る PO number、license number、free-text remarks を surface。

FieldStatusNotesLength
invoiceNumberOptionalmerchant invoice number。
purchaseOrderNumberOptionalmerchant PO number。
licenseNumberOptionalexport/import license number。
certificateNumberOptionalcustoms certificate number。
paymentConditionsOptionalcommercial invoice 表示 free-text terms-of-payment。200 characters 以内 — 超過は printed invoice overflow。
customsRemarksOptionalfree-text customs remarks。
taxCodeOptionallabel に 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:

FieldReturnsUse when
urlrendered label file(PDF)の hosted link。download/print 可能。link を hand off — open、email、または payload なしで後 fetch。
labelImageresponse 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 errors array で 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_WRITECARTON_WRITESHIPMENT_RATING_WRITELANDED_COST_WRITESHIPMENT_WRITE)。Verified Account standard merchant role がすべて grant。

Next steps 

このページは役に立ちましたか?