Creating the batch
The Batch Object contains an array of BatchShipment. The BatchShipment Object acts as a wrapper around the Shipment Object, containing shipment-specific service level information such as carrier and service level. To create a batch, send a JSON request to the Batch endpoint with an array of BatchShipment objects. The following is an example of the request.batch_created. For more information, see our Webhooks tutorial.
Here is a sample of the empty response.
Default service levels vs. per-shipment service levels
When creating your Batch, you can choose to apply one carrier service level for all your Shipments, or specify the service level on a per-shipment bases. Please see our service level tokens in the API reference guide. If you want to set one service levels for all the Shipments in your batch, you can specify the service level token withdefault_servicelevel_token field in your Batch request.
This field can be overridden on a per-shipment basis by filling out the optional servicelevel_token field on the BatchShipment object.
The following is an example of this behavior:
Fix validation issues
Once the Batch Object is created, the status will change from VALIDATING to either VALID or INVALID. If the status is INVALID, that means some BatchShipments in the Batch have errors that need to be fixed before you can purchase labels. To find invalid BatchShipments in the Batch, set theobject_results query parameter on the Batch endpoint to filter by Shipments that have failed. The following is an example of using the object_results query parameter:
object_results query parameter accepts the following values:
- creation_failed
- creation_succeeded
- purchase_succeeded
- purchase_failed
Purchase the batch
To purchase the batch, simply send an empty POST request to the endpoint:batch_purchased to get push notifications when your labels are ready. Again, for more information, see our Webhooks tutorial.
If there are any failed transactions, you can find them directly with the object_results=purchase_failedquery parameter.
When the purchase is complete, you can download the labels as merged files. Each file contains a maximum of 100 labels. The label_url field contains an array of URLs, one URL for each file.
Each file is a PDF file or a ZIP file. The label_filetype of the batch sets the file type. If the batch has no label_filetype, Shippo uses the default label format of your account.
- If
label_filetypeisPDF,PDF_2.3x7.5,PDF_4x6,PDF_4x8,PDF_A4, orPDF_A6, the file is one PDF file that contains all the labels. - If
label_filetypeisPNG,PNG_2.3x7.5,PDF_A5, orZPLII, the file is a ZIP file. The ZIP file contains one file for each label. - If one or more labels in the file are ZPL labels, the file is a ZIP file for all values of
label_filetype.
.pdf or .zip).
Each URL in label_url expires. Before you download a file, read the Expires query parameter on the URL. If Expires is in the past, read the object_created value of the batch:
- If
object_createdis more than one year ago, the file is no longer available. Do not callGET /batches/{BatchId}. - If
object_createdis less than one year ago, callGET /batches/{BatchId}to get newlabel_urlvalues.