Record shipments from your own system
When a warehouse or carrier system knows that a parcel has gone, it can tell Commerce directly, so the order, the stock and your storefront all follow without anyone typing it in. This guide is for that integration.
Make a key
Section titled “Make a key”In Commerce, open Management keys and create one. It belongs to your organization and works on every store’s orders. You can only create one if you can fulfil orders yourself, so nobody can hand out a power they do not hold. The key is shown once, when you make it. You can limit it to the addresses your server calls from.
A management key has one of two levels. Read finds and reads orders, finds a shipment by its carrier’s reference and reads an
order’s fulfilment, and changes nothing. Fulfil does all of that and also records and updates shipments; a key made before the
read level existed is a Fulfil key. Neither can refund, cancel, move an order along or change stock, and no answer ever carries who bought:
no name, email or address. Send the key as a bearer token to /commerce/management/v1. It is for servers, not browsers: a page cannot use it.
Find an order
Section titled “Find an order”List orders returns the organization’s orders, newest first, 50 to a page. Filter by
storeId, status, number (ORD-1001 or 1001), hideTest=true and paidFrom / paidTo, and ask for the next page with page.
An order number is unique only within a store, so without storeId a number can match one order in each store and the answer is a list.
Test orders are included and flagged isTest: skip them, or ask for hideTest=true, because a fulfilment system must not ship one
for real. Read an order returns one in the same shape, with the ids of its lines and
shipments, and Find a shipment by its carrier reference takes the externalReference
you recorded and returns the shipment and the order it belongs to.
Find what there is to ship
Section titled “Find what there is to ship”Read an order’s fulfilment for the order’s id. Its groups are
the lines that follow one workflow, each with an id and lines showing what was ordered, what has shipped and
what was cancelled. You need the group’s id and each line’s id to record a shipment. Your system learns the
order id from your storefront, or from a webhook you add to the order workflow.
Record the shipment
Section titled “Record the shipment”Record a shipment with the group, the lines and how many of each left, and who is carrying it:
{ "groupId": "…", "lines": [{ "orderLineId": "…", "quantity": 2 }], "carrier": "ParcelCo", "trackingNumber": "PC-1", "externalReference": "your-own-id-for-this-shipment"}The order must be paid, and a line cannot ship more than is still to ship. Recording a shipment takes the items off the shelf. When everything in a group has shipped, the group finishes by itself, exactly as when a person records the shipment, and the order’s status follows.
externalReference is your own id for the shipment and carrierPluginKey names the integration that made it:
keep them so you can match a shipment to your own records later.
Follow it
Section titled “Follow it”Update a shipment as it moves: set its status to in_transit,
delivered or exception, or change its tracking. Your storefront reads the same shipment through
Read an order with a delivery key that may read orders, so the buyer sees
the tracking you recorded.
Limits
Section titled “Limits”A key may make 300 requests a minute. A request over it answers 429 with a Retry-After. A revoked key stops
working at once, and the shipments it recorded stay.