A PHP SDK for the BoxC API.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Examples
Resources
.gitignore
Autoload.php
LICENSE
README.md

README.md

PHP SDK for BoxC API

View all of the RESTful API documentation at https://api.boxc.com.

Requirements

Configuration

Set your application settings in the Config class located in \Resources\Config.php. You will find some constants like your APP_ID at https://api.boxc.com/manage. Leave the access_token empty unless you plan on using only one token for every request.

Usage

Below are the basic usage patterns for the SDK. Check out the \Examples directory to see more detailed examples on how to use the SDK and interact with the API. Keep in mind you will need to change the IDs to match your shipments, labels, orders, products and access token.

Autoload

require 'Autoload.php';
// do some stuff

OAuth

require 'Autoload.php';
use Boxc\OAuth;

$return_uri = "/php-api/Examples/access_token.php";
try {
    $authorize_url = (new OAuth())->authorize($return_uri);
    header("Location: $authorize_url");
} catch (Exception $e) {
    echo "Message: " . $e->getMessage() . " | Code: " . $e->getCode();
}

Setting the Access Token

require 'Autoload.php';
$token = "[access_token]";

// Dynamically set the token
Boxc\Config::set_user($token);

// Set the token when instantiating a resource
$response = (new Boxc\Estimate($token))->get($data);

Batch Requests

Instantiate once and set the token dynamically.

require 'Autoload.php';

$estimate = new Boxc\Estimate();

$user_tokens = ['1', '2', '3'];
$params = [
    'weight' => 0.312,
    'height' => 4.5,
    'width' => 8,
    'length' => 10.5,
    'province' => 'NY',
    'country' => 'US'
];

foreach ($user_tokens as $token)
{
    try {
        Boxc\Config::set_user($token);
        print_r($estimate->get($params));
    } catch (Exception $e) {
        // log it
    }
}