Create a shipment
How to create a shipment via API
To create a new shipment, send a POST
request to the /api/shipments
endpoint, passing the resource arguments in the request body.
Request
POST https://yourdomain.commercelayer.io/api/shipments
Arguments
Body Parameter | Type | Required |
---|---|---|
type |
| Required |
attributes.reference |
| Optional |
attributes.reference_origin |
| Optional |
attributes.metadata |
| Optional |
relationships.order |
| Required |
relationships.shipping_category |
| Optional |
relationships.inventory_stock_location |
| Required |
relationships.shipping_address |
| Optional |
relationships.shipping_method |
| Optional |
relationships.tags |
| Optional |
Example
The following request creates a new shipment:
curl -g -X POST \
'https://yourdomain.commercelayer.io/api/shipments' \
-H 'Accept: application/vnd.api+json' \
-H 'Authorization: Bearer your-access-token' \
-H 'Content-Type: application/vnd.api+json' \
-d '{
"data": {
"type": "shipments",
"relationships": {
"order": {
"data": {
"type": "orders",
"id": "ABCRtyUpBa"
}
},
"inventory_stock_location": {
"data": {
"type": "inventory_stock_locations",
"id": "BCDRtyUpBa"
}
}
}
}
}'
On success, the API responds with a 201 Created
status code, returning the created resource object:
{
"data": {
"id": "xYZkjABcde",
"type": "shipments",
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde"
},
"attributes": {
"number": "#1234/S/001",
"status": "draft",
"currency_code": "EUR",
"cost_amount_cents": 1000,
"cost_amount_float": 10.0,
"formatted_cost_amount": "€10,00",
"skus_count": 2,
"selected_rate_id": "rate_f89e4663c3ed47ee94d37763f6d21d54",
"rates": [
{
"id": "rate_f89e4663c3ed47ee94d37763f6d21d54",
"rate": "45.59",
"carrier": "DHLExpress",
"service": "MedicalExpress"
}
],
"purchase_error_code": "SHIPMENT.POSTAGE.FAILURE",
"purchase_error_message": "Account not allowed for this service.",
"get_rates_errors": [
{
"carrier": "DHLExpress",
"message": "to_address.postal_code: Shorter than minimum length 3",
"type": "rate_error"
}
],
"get_rates_started_at": "2018-01-01T12:00:00.000Z",
"get_rates_completed_at": "2018-01-01T12:00:00.000Z",
"purchase_started_at": "2018-01-01T12:00:00.000Z",
"purchase_completed_at": "2018-01-01T12:00:00.000Z",
"purchase_failed_at": "2018-01-01T12:00:00.000Z",
"on_hold_at": "2018-01-01T12:00:00.000Z",
"picking_at": "2018-01-01T12:00:00.000Z",
"packing_at": "2018-01-01T12:00:00.000Z",
"ready_to_ship_at": "2018-01-01T12:00:00.000Z",
"shipped_at": "2018-01-01T12:00:00.000Z",
"created_at": "2018-01-01T12:00:00.000Z",
"updated_at": "2018-01-01T12:00:00.000Z",
"reference": "ANY-EXTERNAL-REFEFERNCE",
"reference_origin": "ANY-EXTERNAL-REFEFERNCE-ORIGIN",
"metadata": {
"foo": "bar"
}
},
"relationships": {
"order": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/order",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/order"
}
},
"shipping_category": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/shipping_category",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/shipping_category"
}
},
"inventory_stock_location": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/inventory_stock_location",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/inventory_stock_location"
}
},
"stock_location": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/stock_location",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/stock_location"
}
},
"origin_address": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/origin_address",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/origin_address"
}
},
"shipping_address": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/shipping_address",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/shipping_address"
}
},
"shipping_method": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/shipping_method",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/shipping_method"
}
},
"delivery_lead_time": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/delivery_lead_time",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/delivery_lead_time"
}
},
"stock_line_items": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/stock_line_items",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/stock_line_items"
}
},
"stock_transfers": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/stock_transfers",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/stock_transfers"
}
},
"line_items": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/line_items",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/line_items"
}
},
"available_shipping_methods": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/available_shipping_methods",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/available_shipping_methods"
}
},
"carrier_accounts": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/carrier_accounts",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/carrier_accounts"
}
},
"parcels": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/parcels",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/parcels"
}
},
"attachments": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/attachments",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/attachments"
}
},
"events": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/events",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/events"
}
},
"tags": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/tags",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/tags"
}
},
"versions": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/relationships/versions",
"related": "https://yourdomain.commercelayer.io/api/shipments/xYZkjABcde/versions"
}
}
},
"meta": {
"mode": "test"
}
}
}
Last updated