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.
Once your purchases are complete, you will be able to download a merged PDF file with the labels. Each PDF file will contain up to 100 labels, the label_url field will contain an array of PDF files.