Batch Shipping Labels
by Sawyer Bateman
Common advice for any startup is to find customers early, and listen to them attentively. Your best customers will steer you towards a business model, and one way to say thank you is by sending them swag! It shouldn't be expensive; generally a clever or well designed t-shirt will do. However, the time cost is likely to be significant if distribution isn"t something you do on a regular basis.
At EasyPost we've been lucky - with access to our own shipping API, generating a label to slap on a parcel is a piece of cake. Today we're sharing our in-house script that anyone can use to process a batch of shipments in minutes!
First, we'll be placing our shipments into a CSV file for processing. The default script configuration is set up for a 7 column layout like so:
Save the resulting CSV in the same folder as this script: easypost_batch_from_csv.rb
The script is already configured with the customs details required to ship a t-shirt internationally, and can be modified to fit your precise needs. At a minimum you'll need to add your "from address", and EasyPost api-key (https://easypost.com/account/api-keys).
The batch is run in two stages, the first initializes the shipments and estimates the cost of the labels:
ruby batch_from_csv_test.rb -i swag.csv
The second step iterates over the batch and purchases the cheapest shipping option for each. By default we're only inspecting USPS options, however please feel free to enable UPS and FedEx accounts if you're interested in throwing them into the mix! Once all of the shipments have been successfully purchased, a single batch label file will be generated for your printing convenience!
ruby batch_from_csv_test.rb -i swag.csv -b
Download Example Batch Label (PDF)
We recommend using your test api-key first to work out any kinks with the addresses you have on file (bonus points for adding EasyPost Address Verification into the first stage of the script!)
It's safe to run the script multiple times on the same CSV - we insert a unique batch identifier so that it's not possible to purchase the same labels multiple times. If you're absolutely sure you'd like to create a new batch feel free to delete the identifier from your CSV before re-running.
If you decide to use EasyPost to send swag to your customers please drop us a line at contact@easypost.com so that we can add you to our next batch!