Shippo is a shipping API that connects you with multiple shipping carriers (such as USPS, UPS, DHL, Canada Post, Australia Post, and many others) through one interface.
You must register for a Shippo account to use our API. It's free to sign up. Only pay to print a live label, test labels are free.
To use the API, you must generate an API Token. In the following examples, replace <YOUR_API_KEY_HERE>
with your own token.
For example.
apiKeyHeader:"shippo_test_595d9cb0c0e14497bf07e75ecfec6c6d"
Shippo external API.: Use this API to integrate with the Shippo service
- SDK Installation
- SDK Example Usage
- Available Resources and Operations
- Error Handling
- Server Selection
The SDK relies on Composer to manage its dependencies.
To install the SDK first add the below to your composer.json
file:
{
"repositories": [
{
"type": "github",
"url": "<UNSET>.git"
}
],
"require": {
"Shippo": "*"
}
}
Then run the following command:
composer update
declare(strict_types=1);
require 'vendor/autoload.php';
use Shippo\API;
$security = '<YOUR_API_KEY_HERE>';
$sdk = API\Shippo::builder()
->setShippoApiVersion('2018-02-08')
->setSecurity($security)->build();
$response = $sdk->addresses->list(
page: 1,
results: 5,
shippoApiVersion: '2018-02-08'
);
if ($response->addressPaginatedList !== null) {
// handle response
}
Available methods
- list - List all addresses
- create - Create a new address
- get - Retrieve an address
- validate - Validate an address
- create - Create a batch
- get - Retrieve a batch
- addShipments - Add shipments to a batch
- purchase - Purchase a batch
- removeShipments - Remove shipments from a batch
- list - List all carrier accounts
- create - Create a new carrier account
- get - Retrieve a carrier account
- update - Update a carrier account
- initiateOauth2Signin - Connect an existing carrier account using OAuth 2.0
- register - Add a Shippo carrier account
- getRegistrationStatus - Get Carrier Registration status
- list - List all customs declarations
- create - Create a new customs declaration
- get - Retrieve a customs declaration
- create - Create a pickup
- get - Retrieve a rate
- listShipmentRates - Retrieve shipment rates
- listShipmentRatesByCurrencyCode - Retrieve shipment rates in currency
- create - Generate a live rates request
- getDefaultParcelTemplate - Show current default parcel template
- updateDefaultParcelTemplate - Update default parcel template
- deleteDefaultParcelTemplate - Clear current default parcel template
- list - List all service groups
- create - Create a new service group
- update - Update an existing service group
- delete - Delete a service group
- list - List all Shippo Accounts
- create - Create a Shippo Account
- get - Retrieve a Shippo Account
- update - Update a Shippo Account
- list - List all user parcel templates
- create - Create a new user parcel template
- delete - Delete a user parcel template
- get - Retrieves a user parcel template
- update - Update an existing user parcel template
- createWebhook - Create a new webhook
- listWebhooks - List all webhooks
- getWebhook - Retrieve a specific webhook
- updateWebhook - Update an existing webhook
- deleteWebhook - Delete a specific webhook
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.
By default an API error will raise a Errors\SDKError
exception, which has the following properties:
Property | Type | Description |
---|---|---|
$message |
string | The error message |
$statusCode |
int | The HTTP status code |
$rawResponse |
?\Psr\Http\Message\ResponseInterface | The raw HTTP response |
$body |
string | The response content |
When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the initiateOauth2Signin
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
Errors\InitiateOauth2SigninResponseBody | 400 | application/json |
Errors\InitiateOauth2SigninCarrierAccountsResponseBody | 401 | application/json |
Errors\InitiateOauth2SigninCarrierAccountsResponseResponseBody | 404 | application/json |
Errors\SDKError | 4XX, 5XX | */* |
declare(strict_types=1);
require 'vendor/autoload.php';
use Shippo\API;
use Shippo\API\Models\Operations;
$security = '<YOUR_API_KEY_HERE>';
$sdk = API\Shippo::builder()
->setShippoApiVersion('2018-02-08')
->setSecurity($security)->build();
try {
$request = new Operations\InitiateOauth2SigninRequest(
carrierAccountObjectId: '<id>',
redirectUri: 'https://enlightened-mortise.com/',
);
$response = $sdk->carrierAccounts->initiateOauth2Signin(
request: $request
);
if ($response->statusCode === 200) {
// handle response
}
} catch (Errors\InitiateOauth2SigninResponseBodyThrowable $e) {
// handle $e->$container data
throw $e;
} catch (Errors\InitiateOauth2SigninCarrierAccountsResponseBodyThrowable $e) {
// handle $e->$container data
throw $e;
} catch (Errors\InitiateOauth2SigninCarrierAccountsResponseResponseBodyThrowable $e) {
// handle $e->$container data
throw $e;
} catch (Errors\SDKError $e) {
// handle default exception
throw $e;
}
The default server can also be overridden globally using the setServerUrl(string $serverUrl)
builder method when initializing the SDK client instance. For example:
declare(strict_types=1);
require 'vendor/autoload.php';
use Shippo\API;
$security = '<YOUR_API_KEY_HERE>';
$sdk = API\Shippo::builder()
->setServerURL("https://api.goshippo.com")
->setShippoApiVersion('2018-02-08')
->setSecurity($security)->build();
$response = $sdk->addresses->list(
page: 1,
results: 5,
shippoApiVersion: '2018-02-08'
);
if ($response->addressPaginatedList !== null) {
// handle response
}
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!
Connect with multiple different carriers, get discounted shipping labels, track parcels, and much more with just one integration. You can use your own carrier accounts or take advantage of our discounted rates with the Shippo carrier accounts. Using Shippo makes it easy to deal with multiple carrier integrations, rate shopping, tracking and other parts of the shipping workflow. We provide the API and web app for all your shipping needs.