name: label-purchase description: Purchase domestic and international shipping labels, handle customs declarations, return labels, and void/refund labels via the Shippo API
Label Purchase
Purchases Are Live
Label purchases charge the authorized Shippo account for real. Before purchasing, explicitly state "this will charge your Shippo account" with the carrier, service, and cost, and require the user to acknowledge. Do not purchase without that confirmation.
Purchase Confirmation Gate
Before every call to CreateTransaction, summarize the following and ask the user for explicit confirmation:
- Carrier and service level
- Estimated cost
- Estimated delivery time
- Origin and destination
Do not proceed without explicit user confirmation.
Domestic Label
- Optionally validate both addresses with
ValidateAddress(see Address Validation). - Call
CreateShipmentwithaddress_from,address_to(as inline address objects using v1 field names --street1,city,state,zip,country),parcels, andasync: false. - Present rates to the user. Let them choose.
- Confirm purchase (see Purchase Confirmation Gate above).
- Call
CreateTransactionwith:rate(selected rate object_id),label_file_type(defaultPDF_4x6),async: false. - Check response
status:SUCCESS: returntracking_number,label_url(display the COMPLETE URL -- S3 signed URLs break if truncated), andtracking_url_provider.QUEUED/WAITING: pollGetTransactionuntil resolved.ERROR: report messages from themessagesarray.
International Label
All domestic steps apply, plus customs handling before shipment creation. See references/customs-guide.md for the full customs workflow.
- Optionally validate addresses with
ValidateAddress. Sender must includeemailandphone. Ask if missing. - Create customs items: call
CreateCustomsItemper item (description, quantity, net_weight, mass_unit, value_amount, value_currency, origin_country, tariff_number). Alternatively, you can skip this step and pass inline item objects directly in the declaration (step 3). - Create the customs declaration: call
CreateCustomsDeclarationwith contents_type, non_delivery_option, certify: true, certify_signer, and the items (either object_ids from step 2, or inline item objects). Seereferences/customs-guide.mdfor field details. - Call
CreateShipmentwith all standard fields pluscustoms_declaration(the declaration object_id). - Present rates, confirm purchase (see Purchase Confirmation Gate), then purchase label and return results as in the domestic flow.
Contents Type Decision Tree
Use this to determine the correct contents_type value:
| Scenario | Value |
|---|---|
| Selling to the recipient (commercial sale) | MERCHANDISE |
| Sending a free gift | GIFT |
| Sending a product sample | SAMPLE |
| Paper documents only | DOCUMENTS |
| Customer returning a purchased item | RETURN_MERCHANDISE |
| Charitable donation | HUMANITARIAN_DONATION |
| None of the above | OTHER (requires contents_explanation) |
Incoterms Decision Logic
The incoterm field on the customs declaration controls who pays duties and taxes:
- B2C / e-commerce (default): Use
DDU(Delivered Duty Unpaid) -- recipient pays duties at delivery. - Seller prepays duties: Use
DDP(Delivered Duty Paid) -- seller covers all duties and taxes. - FedEx/DHL only:
FCA(Free Carrier) is available for advanced trade scenarios.
If the user does not specify, default to DDU for standard e-commerce shipments.
Return Labels
To generate a return label, swap address_from and address_to so the original recipient becomes the sender and the original sender becomes the recipient. All other steps (shipment creation, rate selection, label purchase) remain the same.
Label Format Options
Default to PDF_4x6 unless the user specifies otherwise. Supported formats: PDF_4x6, PDF_4x8, PDF_A4, PDF_A5, PDF_A6, PDF, PDF_2.3x7.5, PNG, PNG_2.3x7.5, ZPLII.
Label Customization Options
When purchasing a label via CreateTransaction, the following options may be set on the shipment or rate:
- Signature confirmation: set
signature_confirmationon the shipment'sextrafield. Values:STANDARD,ADULT,CERTIFIED,INDIRECT,CARRIER_CONFIRMATION. - Insurance: set
insuranceon the shipment'sextrafield withamount,currency, andprovider. - Saturday delivery: set
saturday_deliverytotruein the shipment'sextrafield. Only supported by certain carriers and service levels. - Reference fields: pass
metadataon the transaction for order numbers or internal references.
Label from Existing Rate
If the user already has a rate object_id: optionally call GetRate to confirm details, then confirm purchase (see Purchase Confirmation Gate), then call CreateTransaction directly.
Voiding a Label
Call CreateRefund with the transaction object_id.
Refund limitations: Void/refund eligibility depends on carrier and timing. Not all labels can be refunded after purchase. If CreateRefund fails, advise the user to contact Shippo support.
Quick Reference
Domestic label:
(optional) ValidateAddress (x2) -> CreateShipment (with inline addresses) -> user picks rate -> confirm -> CreateTransaction
International label:
(optional) ValidateAddress (x2) -> CreateCustomsItem (per item) -> CreateCustomsDeclaration -> CreateShipment (with inline addresses + customs_declaration) -> user picks rate -> confirm -> CreateTransaction
Return label:
Same as domestic/international, but swap address_from and address_to.
Order-to-label:
CreateOrder -> CreateShipment (using order address/item data) -> user picks rate -> confirm -> CreateTransaction -> packing slip (REST fallback, see below)
Orders and Packing Slips
Use orders to represent e-commerce fulfillment requests. An order captures the shipping address, line items, and totals -- then feeds into the standard label purchase workflow.
Tools
CreateOrder: Create an order with line items, shipping address, and order details.GetOrder: Retrieve an order by its object_id.ListOrders: List all orders.- Packing slip (known gap): Generate a packing slip PDF for an order. There is no packing-slip tool in the MCP catalog. The underlying REST endpoint exists at
GET /orders/{ORDER_ID}/packingslip/(returns a 24-hour S3 PDF link). Fall back to a direct REST call, or advise the user to use the Shippo dashboard until the MCP gap is closed.
Workflow
- Call
CreateOrderwith the shipping address, line items (title, quantity, sku, total_price, etc.), and order-level fields. - Use the order's address and item data to call
CreateShipment, then follow the standard label purchase flow (rate selection, confirmation,CreateTransaction). - After purchasing the label, generate a packing slip via the REST fallback (see Tools above for the known MCP gap).