Skip to main content

Merge Orders

mailhub_merge_orders

Merge 2 to 25 Orders into one new Shipment, packed in one box and bought with one Label. Use Orders that mailhub_find_merge_candidates lists as available. The Orders stay separate Orders, each with its own identifier and status; what they share is the Shipment, its parcel, its Rates, and its Label.

Permission and safety​

Changes dataYes
ConfirmationRequired — confirm: true
Spends fundsNo
PermissionUpdate access to Orders

Confirmation is enforced by the server — see Confirmations & Spend Safety. Merging buys nothing: postage is still a separate mailhub_buy_label call. Asking for the same merge again answers with the same Shipment.

Input​

FieldTypeRequiredDefaultNotes
anchorOrderIdstringYes—The Order to start the merge from; its addresses are copied onto the Shipment
orderIdsarray of stringsYes—Every Order to merge, the anchor included — 2 to 25 Order UUIDs
parcelobjectNo—The box for the merged Shipment, in the same shape as on mailhub_create_order
confirmbooleanNofalseDefaults to false; the call is refused unless the value is the boolean true

Without a parcel, the box takes the anchor's size and the Orders' weights added together.

Example input​

{
"anchorOrderId": "11111111-1111-1111-1111-111111111111",
"orderIds": [
"11111111-1111-1111-1111-111111111111",
"22222222-2222-2222-2222-222222222222"
],
"confirm": true
}

Output​

The merged Shipment and its Orders, passed through from Mailhub, with a note that one Label will cover every Order in it. Use the merged Shipment's identifier from here on: rate it with mailhub_get_shipment_rates.

Rules and common tool-specific errors​

  • Fewer than two Orders is refused with MCP_MISSING_FIELD before Mailhub is called.
  • An Order that cannot be merged refuses the whole merge with Order.MergeRefused. The result does not say which Order was refused or why: call mailhub_find_merge_candidates to see which Orders are unavailable and their unavailableReason.
  • Every Order must be Draft or Created, ship within the US, and go to the same recipient from the same source — the REST guide has the full rules.
  • Access and shared failures — sign-in, permissions, rate guards — are listed in Errors & Troubleshooting.

Next​