International Shipments
International (cross border) shipments are as easy as domestic ones
Getting Started
In this example, we will use Guzzle, a popular HTTP client written in PHP.
First, start with installing Guzzle to your project using Composer. At time of writing, version 7.0 is the latest stable. If you're using Laravel, a popular PHP framework, then Guzzle is already installed and Laravel actually provides an expressive API on top of it.
composer require guzzlehttp/guzzle:^7.0Once you're done, start a new php file:
<?phpPre-requisites
Before you can start issuing commands and creating shipments! we need you to have the following ready:
Your API token is considered as sensitive as your password, do not share it or save it in your source code system
Your Service Variables: Depending on your account type, contract, available rates and your geo location, there are one or more services available for you. Refer to eship ➜ API page for more details. Every request must have at least one "Base Product" associated. The value section represent the UUID or unique identifier of the service you want to request, which you will need later
Collection Address: Every address you enter to our system will be given a unique identifier, using the same UUID format explained above. Many customers have only a single collection address. The value of that address is also unique, and it doesn't change with minor modifications. However, if you're planning to change your collection address completely, please create a new one.
Other considerations
To be updated
Setting up the client
Now that we have the initial variables handy, let's create the HTTP client object:
A few observations
$api_baseis the main API URL, you can get this value from the API Docs, for the majority of the customers, it's the one mentioned above$api_tokenis the variable holding your API Token, you can inject it the way you want, including hardcoding it temporarilybase_uriallows us to tell the client about the main URL and use relative endpoints thereafterheadersis where we configure the client to use the default method of auth for all subsequent requests, using theAuthorizationheader, and make sure to send JSON requests to all endpoints.
The first test
Next, we'll make the very first request, which will return back the account info and confirm that we're able to connect and authenticate:
A typical response to this request is something along these lines:
This is a standard, successful JSON response. And while some response fields were omitted for brevity, you get the idea.
If you get GuzzleHttp\Exception\ClientException or with a message starting with Cannot Authenticate: or a status code 401, then you need to double check your API Token
To inspect the response and get the results in PHP object (or array) format, use the following snippet
It is important though to check for errors before proceeding with parsing the response body:
The 1st shipment
Okay, so far we have the client ready and the first request successful, let's dive into creating an actual shipment, well, maybe a test one first.
Full example code
Follow the comments for a quick explanation, this example will ultimately create an actual shipment if you remove the test field from the request.
Happy shipping!!
Last updated
Was this helpful?