Confirm And Buy Labels

Before the shipment process can be started, a transaction needs to take place which is buying labels.

Confirm Shipments and Buy Labels

Now that you have your easyship_shipment_id, you can call the Label endpoint to confirm the shipment and purchase the label.

{
  "shipments": [
    {
      "easyship_shipment_id": "ESTEST00000",
    }
  ]
}
curl --include \
     --request POST \
     --header "Content-Type: application/json" \
     --header "Authorization: Bearer  <YOUR EASYSHIP API TOKEN>" \
     --data-binary "{
  \"shipments\": [
    {
      \"easyship_shipment_id\": \"ESUS3171766\",
      \"courier_id\": \"b4552ed2-ae95-4647-9746-5790bf252c7f\"
    },
    {
      \"easyship_shipment_id\": \"ESUS2513756\"
    }
  ]
}" \
'https://api.easyship.com/label/v1/labels'
require 'rubygems' if RUBY_VERSION < '1.9'
require 'rest_client'

values = '{
  "shipments": [
    {
      "easyship_shipment_id": "ESUS3171766",
      "courier_id": "b4552ed2-ae95-4647-9746-5790bf252c7f"
    },
    {
      "easyship_shipment_id": "ESUS2513756"
    }
  ]
}'

headers = {
  :content_type => 'application/json',
  :authorization => 'Bearer  <YOUR EASYSHIP API TOKEN>'
}

response = RestClient.post 'https://api.easyship.com/label/v1/labels', values, headers
puts response
var request = require('request');

request({
  method: 'POST',
  url: 'https://api.easyship.com/label/v1/labels',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer  <YOUR EASYSHIP API TOKEN>'
  },
  body: "{  \"shipments\": [    {      \"easyship_shipment_id\": \"ESUS3171766\",      \"courier_id\": \"b4552ed2-ae95-4647-9746-5790bf252c7f\"    },    {      \"easyship_shipment_id\": \"ESUS2513756\"    }  ]}"
}, function (error, response, body) {
  console.log('Status:', response.statusCode);
  console.log('Headers:', JSON.stringify(response.headers));
  console.log('Response:', body);
});
from urllib2 import Request, urlopen

values = """
  {
    "shipments": [
      {
        "easyship_shipment_id": "ESUS3171766",
        "courier_id": "b4552ed2-ae95-4647-9746-5790bf252c7f"
      },
      {
        "easyship_shipment_id": "ESUS2513756"
      }
    ]
  }
"""

headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer  <YOUR EASYSHIP API TOKEN>'
}
request = Request('https://api.easyship.com/label/v1/labels', data=values, headers=headers)

response_body = urlopen(request).read()
print response_body
<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.easyship.com/label/v1/labels");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_POSTFIELDS, "{
  \"shipments\": [
    {
      \"easyship_shipment_id\": \"ESUS3171766\",
      \"courier_id\": \"b4552ed2-ae95-4647-9746-5790bf252c7f\"
    },
    {
      \"easyship_shipment_id\": \"ESUS2513756\"
    }
  ]
}");

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  "Content-Type: application/json",
  "Authorization: Bearer  <YOUR EASYSHIP API TOKEN>"
));

$response = curl_exec($ch);
curl_close($ch);

var_dump($response);

You'll receive a response with the status of the label pending, generated, failed or not generated.

📘

As the labels and customs documents are generated asynchronously, we will use the callback URL that you provide in your Easyship dashboard or the company endpoint, to notify you that they are ready. For more information on asynchronous responses please see Asynchronous Responses

The response below contains your shipping label in .pdf format, ready for you to download, print and attach to your parcel!

"message": "Your labels are being generated",
  "total_cost": 76,
  "available_balance": 924,
  "labels": [
{
    "labels": {
        "easyship_shipment_id": "ESTEST00000",
        "label_state": "generated",
        "status": "success",
        "label_url": "https://goeasyship.s3.amazonaws.com/ESTEST00000_label.pdf",
        "tracking_number":      '12345',
        "tracking_page_url":    'https://www.easyship.com/shipment-tracking/ESHK0040989'
    }
  ]
}

And that's it! You've requested rates, passed through an order and purchased a shipping label.

View your label here!


What’s Next

Your first shipment has been created and labelled, now you can check out more advanced features like arranging courier pick ups, checking for tracking updates, updating your shipments and managing your account!