Skip to content

goshippo/shippo-php-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shippo logo Shippo PHP SDK

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"

Summary

Shippo external API.: Use this API to integrate with the Shippo service

Table of Contents

SDK Installation

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

SDK Example Usage

Example

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 Resources and Operations

Available methods
  • list - List all addresses
  • create - Create a new address
  • get - Retrieve an address
  • validate - Validate an address
  • list - List all carrier parcel templates
  • get - Retrieve a carrier parcel templates
  • list - List all customs declarations
  • create - Create a new customs declaration
  • get - Retrieve a customs declaration
  • list - List all customs items
  • create - Create a new customs item
  • get - Retrieve a customs item
  • list - List all manifests
  • create - Create a new manifest
  • get - Retrieve a manifest
  • list - List all orders
  • create - Create a new order
  • get - Retrieve an order
  • list - List all parcels
  • create - Create a new parcel
  • get - Retrieve an existing parcel
  • create - Create a refund
  • list - List all refunds
  • get - Retrieve a refund
  • 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 shipments
  • create - Create a new shipment
  • get - Retrieve a shipment
  • list - List all Shippo Accounts
  • create - Create a Shippo Account
  • get - Retrieve a Shippo Account
  • update - Update a Shippo Account
  • create - Register a tracking webhook
  • get - Get a tracking status
  • list - List all shipping labels
  • create - Create a shipping label
  • get - Retrieve a shipping label
  • 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

Error Handling

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 */*

Example

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;
}

Server Selection

Override Server URL Per-Client

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
}

Development

Maturity

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.

Contributions

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!

About Shippo

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published