Process bulk shipments from CSV files, create and purchase batch labels, and generate end-of-day manifests via the Shippo API
Batch purchases charge the authorized Shippo account for real. Before PurchaseBatch, show the shipment count, carrier/service, and estimated total cost, and require explicit user confirmation.
Before every call to PurchaseBatch, summarize the following and ask the user for explicit confirmation:
Do not proceed without explicit user confirmation.
See shippo/references/csv-format.md for the column specification.
shippo/references/customs-guide.md. Use correct customs enum values: RETURN_MERCHANDISE (not RETURN) for returned goods, HUMANITARIAN_DONATION (not HUMANITARIAN) for charitable donations.batch_shipments array with inline address and parcel objects per row.CreateBatch with the array.GetBatch until status is VALID or INVALID. See Polling Intervals below.INVALID, some batch shipments failed validation: see "Fixing an INVALID batch" below, fix them, and re-poll until VALID. Report per-shipment failures either way before proceeding.PurchaseBatch to buy labels for all valid shipments.GetBatch until status changes from PURCHASING to PURCHASED. See Polling Intervals below.A purchased batch does not put each label URL inline on the batch object. Each entry in batch_shipments[] carries a transaction field, which is a Transaction object_id. Call GetTransaction on it to get that shipment's label_url and tracking_number. The batch-level label_url is a merged multi-label PDF (up to 100 labels per file) and cannot be split per order.
For batches over 500 shipments, consider splitting into multiple batches. Large batches take longer to validate and purchase, and a single failure can be harder to diagnose.
GetBatch with the batch object_id.CreateShipment per shipment to get rate quotes (see Rate Shopping).batch_shipments with servicelevel_token per item.AddShipmentsToBatch (before purchase only). Note: adding an invalid shipment will change the entire batch status to INVALID. Check per-shipment statuses after adding.RemoveShipmentsFromBatch (before purchase only).If GetBatch returns status INVALID, one or more batch shipments failed validation and the batch cannot be purchased until they are fixed.
GetBatch with object_results=creation_failed to return only the failed shipments (paginate with ?page= if there are many), or read each batch_shipments[].status (VALID / INVALID / INCOMPLETE / TRANSACTION_FAILED) and its messages for the reason. The batch-level errors array collects the same per-shipment failures in one place.RemoveShipmentsFromBatch with the failed batch-shipment object_ids (from batch_shipments[].object_id, not the shipment object_id) to drop them, orAddShipmentsToBatch with corrected shipment objects (fixed address, parcel, or servicelevel).GetBatch until status is VALID.PurchaseBatch.carrier_account (object_id), shipment_date (YYYY-MM-DD, default today), address_from (pickup address).CreateManifest.GetManifest until status is SUCCESS or ERROR.CSV batch:
Parse CSV -> CreateCustomsDeclaration (international rows) -> CreateBatch -> poll GetBatch -> confirm -> PurchaseBatch -> poll GetBatch
Manifest:
CreateManifest (with transaction object_ids) -> poll GetManifest