NAV
php

Introduction

Welcome to the NEW togo420.com API Reference Center! You can use our APIs to access our various API endpoints, which will allow you to place orders and view order details.

Code examples are available to the right, and you can toggle between programming languages via the tabs at the top right.

Authentication

You will need an API KEY to access each API endpoint. Simply register at our Developer Dashboard to receive your API KEY(s) and start testing/developing using our endpoints.

Environments

There are two environments available: production and sandbox. Testing and development should be done against the sandbox environment/API. This is an environment where you can create and submit orders without incurring any costs. All orders submitted to the production environment/API will be processed and your credit card charged.

Requests should always be made over HTTPS. Connections cannot be made via HTTP. Please note that support for SSL 3.0 has been disabled and we recommend using TLS 1.2 or better.

Production

API Endpoint: https://api.togo420.com/v1

Dashboard: https://dashboard.togo420.com

Sandbox (testing)

API Endpoint: https://sandbox.togo420.com/v1

Dashboard: https://sandbox-dashboard.togo420.com

Callbacks

togo420.com can make callbacks to a custom URL whenever the status of one of your orders changes.

Setup your callback URL under the Integrations section of the Dashboard.

togo420.com will make a JSON formatted HTTPS POST to your chosen URL with the following parameters.

Query Parameters

Parameter Type Description
orderId integer The togo420.com order ID.
environment string The environment from which the callback originated, either LIVE or SANDBOX.
timestamp datetime The time the change took place.
status string The current status of the order. One of NotYetSubmitted, Submitted, Complete, or Cancelled.
delivery string Each delivery in the order. Note that this can be empty if the deliveries have not yet been allocated, and it may change. You will receive a callback each time a new delivery is created, or a delivery status changes.

Orders

Create an Order

<?php
$merchantID = "yourMerchantID";
$apiKEY = "yourAPIKEY";

$countryCode = "US";
$recipientName = "";
$address1 = "";
$address2 = "";
$addressTownOrCity = "";
$stateOrCounty = "";
$postalOrZipCode = "";
$preferredShippingMethod = "";

$endpointURL = "https://sandbox.togo420.com/v1/createOrder";
$data = array('merchantOrderId' => $merchantOrderID,'countryCode' => $countryCode, 'recipientName' => $recipientName, 'address1' => $address1 , 'address2' => $address2, 'addressTownOrCity' => $addressTownOrCity, 'stateOrCounty' => $stateOrCounty, 'postalOrZipCode' => $postalOrZipCode, 'preferredShippingMethod' => $preferredShippingMethod);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpointURL . "?" . http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-merchant-id:' . $merchantID, 'x-api-key:' . $apiKEY, 'Content-Type:application/json'));
$response = json_decode(curl_exec($ch), true);
print_r($response);
?>

Make sure to update/replace the API KEY where appropriate. The above PHP code example returns a JSON structured like this:

{
    "data": [
        {
            "orderID": "ZJH9406469335036501016",
            "environmentType": "sandbox",
            "shipTo": "Ship To Name",
            "shippingAddress": "1111 Test Street #2020",
            "shippingAddress2": "",
            "shippingCity": "Boulder",
            "shippingState": "Colorado",
            "shippingZip": "80301",
            "shippingCountry": "US",
            "shippingAmount": "$0.00",
            "orderTotal": "$0.00",
            "products": []
        }
    ],
    "statusText": "OK",
    "statusCode": "200"
}

Make a POST call to /v1/createOrder. You will get back a unique order ID, which you will need for adding products to the order.

HTTP Request

POST https://sandbox.togo420.com/v1/createOrder

Query Parameters

Parameter Type Description
x-merchant-id string Your MerchantID provided via the Developer Dashboard.
x-api-key string API Key provided via either the LIVE or Sandbox Developer Dashboards.
merchantOrderId string Your identifier for this order (ie: your internal Invoice/PO number).
recipientName string Recipient name.
address1 string First line of recipient address.
address2 string Second line of recipient address.
addressTownOrCity string Town or City of the recipient.
stateOrCounty string State, county or region of the recipient.
postalOrZipCode string Postal or zip code of the recipient.
countryCode string Two-letter country code of the recipient. Possible value is US for now as we only ship within the US.
preferredShippingMethod string Possible values are Budget, Standard, Express, and Overnight.

Add a Product

<?php
$merchantID = "yourMerchantID";
$apiKEY = "yourAPIKEY";

$ORDER_ID = "123123";
$locationId = "bo111";
$sku = "bwc_choc1";
$quantity = 4;

$endpointURL = "https://sandbox.togo420.com/v1/addProduct";
$data = array('orderId' => $ORDER_ID,'sku' => $sku,'locationId' => $locationId, 'quantity' => $quantity);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpointURL . "?" . http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-merchant-id:' . $merchantID, 'x-api-key:' . $apiKEY, 'Content-Type:application/json'));
$response = json_decode(curl_exec($ch), true);
print_r($response);

Make sure to update/replace the API KEY where appropriate. The above PHP code example returns a JSON structured like this:

{
    "data": [
        {
            "orderID": "ZJH9406469335036501016",
            "environmentType": "sandbox",
            "shipTo": "Ship To Name",
            "shippingAddress": "1111 Test Street #2020",
            "shippingAddress2": "",
            "shippingCity": "Boulder",
            "shippingState": "Colorado",
            "shippingZip": "80301",
            "shippingCountry": "US",
            "salesTax": "$4.00",
            "shippingAmount": "$4.00",
            "orderTotal": "$27.96",
            "products": [
                {
                    "stateCode": "CO",
                    "sku": "bwc_choc1",
                    "yourCost": "$4.99",
                    "quantity": "4",
                    "productName": "Chocolate Edibles",
                    "productDescription": "Long Description here",
                    "productImage": "https:\/\/s3-us-west-1.amazonaws.com\/celebsncdn1\/chocolate.png"
                }
            ]
        }
    ],
    "statusText": "OK",
    "statusCode": "200"
}

Make a POST call to /v1/addProduct. This will add a product sku to your order. An error will occur when attempting to add a product from different inventory locations (ie: all products in an order must originate from the same inventory location/city).

HTTP Request

POST https://sandbox.togo420.com/v1/addProduct

Query Parameters

Parameter Type Description
x-merchant-id string Your MerchantID provided via the Developer Dashboard.
x-api-key string API Key provided via either the LIVE or Sandbox Developer Dashboards.
orderId integer The order ID you created and want to add this product to.
locationId string Unique location identification code for the product you want to add.
sku string Unique identification code for the product you want to add.
quantity integer Quantity of product you want to order.

Submit an Order

<?php
$merchantID = "yourMerchantID";
$apiKEY = "yourAPIKEY";

$ORDER_ID = "123123";
$status = "Submitted";

$endpointURL = "https://sandbox.togo420.com/v1/updateOrder";
$data = array('orderId' => $ORDER_ID, 'status' => $status);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpointURL . "?" . http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-merchant-id:' . $merchantID, 'x-api-key:' . $apiKEY, 'Content-Type:application/json'));
$response = json_decode(curl_exec($ch), true);
print_r($response);
?>

Make sure to update/replace the API KEY where appropriate. The above PHP code example returns a JSON structured like this:

{
    "data": [
        {
            "orderID": "ZJH9406469335036501016",
            "environmentType": "sandbox",
            "shipTo": "Ship To Name",
            "shippingAddress": "1111 Test Street #2020",
            "shippingAddress2": "",
            "shippingCity": "Boulder",
            "shippingState": "Colorado",
            "shippingZip": "80301",
            "shippingCountry": "US",
            "salesTax": "$4.00",
            "shippingAmount": "$4.00",
            "orderTotal": "$27.96",
            "products": [
                {
                    "stateCode": "CO",
                    "sku": "bwc_choc1",
                    "yourCost": "$4.99",
                    "quantity": "4",
                    "productName": "Chocolate Edibles",
                    "productDescription": "Long Description here",
                    "productImage": "https:\/\/s3-us-west-1.amazonaws.com\/celebsncdn1\/chocolate.png"
                }
            ]
        }
    ],
    "statusText": "OK",
    "statusCode": "200"
}

Make a POST call to /v1/updateOrder to update the status of an order, for example to submit or cancel the order.

HTTP Request

POST https://sandbox.togo420.com/v1/updateOrder

Query Parameters

Parameter Type Description
x-merchant-id string Your MerchantID provided via the Developer Dashboard.
x-api-key string API Key provided via either the LIVE or Sandbox Developer Dashboards.
orderId integer The order ID you created.
status string Valid values are Cancelled or Submitted.

View an Order

<?php
$merchantID = "yourMerchantID";
$apiKEY = "yourAPIKEY";

$ORDER_ID = "123123";
$endpointURL = "https://sandbox.togo420.com/v1/viewOrder";
$data = array('orderId' => $ORDER_ID);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpointURL . "?" . http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-merchant-id:' . $merchantID, 'x-api-key:' . $apiKEY, 'Content-Type:application/json'));
$response = json_decode(curl_exec($ch), true);
print_r($response);
?>

Make sure to update/replace the API KEY where appropriate. The above PHP code example returns a JSON structured like this:

{
    "data": [
        {
            "orderID": "ZJH9406469335036501016",
            "environmentType": "sandbox",
            "shipTo": "Ship To Name",
            "shippingAddress": "1111 Test Street #2020",
            "shippingAddress2": "",
            "shippingCity": "Boulder",
            "shippingState": "Colorado",
            "shippingZip": "80301",
            "shippingCountry": "US",
            "salesTax": "$4.00",
            "shippingAmount": "$4.00",
            "orderTotal": "$27.96",
            "products": [
                {
                    "stateCode": "CO",
                    "sku": "bwc_choc1",
                    "yourCost": "$4.99",
                    "quantity": "4",
                    "productName": "Chocolate Edibles",
                    "productDescription": "Long Description here",
                    "productImage": "https:\/\/s3-us-west-1.amazonaws.com\/celebsncdn1\/chocolate.png"
                }
            ]
        }
    ],
    "statusText": "OK",
    "statusCode": "200"
}

Make a GET call to /v1/viewOrder to retrieve information about a single order.

HTTP Request

GET https://sandbox.togo420.com/v1/viewOrder

Query Parameters

Parameter Type Description
x-merchant-id string Your MerchantID provided via the Developer Dashboard.
x-api-key string API Key provided via either the LIVE or Sandbox Developer Dashboards.
orderId integer The order ID you created.

List Orders

<?php
$merchantID = "yourMerchantID";
$apiKEY = "yourAPIKEY";

$endpointURL = "https://sandbox.togo420.com/v1/listOrders";
$limit = 2;
$start = 0;
$data = array('limit' => $limit, 'start' => $start);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpointURL . "?" . http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-merchant-id:' . $merchantID, 'x-api-key:' . $apiKEY, 'Content-Type:application/json'));
//$response = json_decode(curl_exec($ch), true);
$response = curl_exec($ch);
print_r($response);
?>

Make sure to update/replace the API KEY where appropriate. The above PHP code example returns a JSON structured like this:

{
    "data": [
        {
            "orderID": "ZJH9406469335036501016",
            "environmentType": "sandbox",
            "shipTo": "Ship To Name",
            "shippingAddress": "1111 Test Street #2020",
            "shippingAddress2": "",
            "shippingCity": "Boulder",
            "shippingState": "Colorado",
            "shippingZip": "80301",
            "shippingCountry": "US",
            "salesTax": "$4.00",
            "shippingAmount": "$4.00",
            "orderTotal": "$27.96",
            "products": [
                {
                    "stateCode": "CO",
                    "sku": "bwc_choc1",
                    "yourCost": "$4.99",
                    "quantity": "4",
                    "productName": "Chocolate Edibles",
                    "productDescription": "Long Description here",
                    "productImage": "https:\/\/s3-us-west-1.amazonaws.com\/celebsncdn1\/chocolate.png"
                }
            ]
        },
        {
            "orderID": "DKT7490039207774081016",
            "environmentType": "sandbox",
            "shipTo": "Ship To Name",
            "shippingAddress": "1111 Test Street #2020",
            "shippingAddress2": "",
            "shippingCity": "Boulder",
            "shippingState": "Colorado",
            "shippingZip": "80301",
            "shippingCountry": "US",
            "salesTax": "$4.00",
            "shippingAmount": "$4.00",
            "orderTotal": "$27.96",
            "products": [
                {
                    "stateCode": "CO",
                    "sku": "bwc_choc1",
                    "yourCost": "$4.99",
                    "quantity": "4",
                    "productName": "Chocolate Edibles",
                    "productDescription": "Long Description here",
                    "productImage": "https:\/\/s3-us-west-1.amazonaws.com\/celebsncdn1\/chocolate.png"
                }
            ]
        }
    ],
    "statusText": "OK",
    "statusCode": "200"
}

Make a GET call to /v1/listOrders to retrieve multiple orders, most recent first.

Note that calls that return potentially more than one result may omit shipping information from the results if the order hasn't yet been processed.

HTTP Request

GET https://sandbox.togo420.com/v1/listOrders

Query Parameters

Parameter Type Description
x-merchant-id string Your MerchantID provided via the Developer Dashboard.
x-api-key string API Key provided via either the LIVE or Sandbox Developer Dashboards.
limit integer Number of orders to return. Default 100, max 250.
start integer Start position used for paginating order list. Default 0.

States

List States

<?php
$merchantID = "yourMerchantID";
$apiKEY = "yourAPIKEY";

$endpointURL = "https://sandbox.togo420.com/v1/states";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpointURL . "?" . http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-merchant-id:' . $merchantID, 'x-api-key:' . $apiKEY, 'Content-Type:application/json'));
$response = json_decode(curl_exec($ch), true);
print_r($response);
?>

Make sure to update/replace the API KEY where appropriate. The above PHP code example returns a JSON structured like this:

{
    "data": [
        {
            "stateCode": "CA",
            "stateName": "California"
        },
        {
            "stateCode": "MI",
            "stateName": "Michigan"
        },
        {
            "stateCode": "NV",
            "stateName": "Nevada"
        },
        {
            "stateCode": "OR",
            "stateName": "Oregon"
        }
    ],
    "statusText": "OK",
    "statusCode": "200"
}

Make a GET call to /v1/states to retrieve the list of all states we currently ship within.

HTTP Request

GET https://sandbox.togo420.com/v1/states

Query Parameters

Parameter Type Description
x-merchant-id string Your MerchantID provided via the Developer Dashboard.
x-api-key string API Key provided via either the LIVE or Sandbox Developer Dashboards.

Catalogue

List Products

<?php
$merchantID = "yourMerchantID";
$apiKEY = "yourAPIKEY";

$endpointURL = "https://sandbox.togo420.com/v1/catalogue";
$data =  array('stateCode' => 'CO');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpointURL . "?" . http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-merchant-id:' . $merchantID, 'x-api-key:' . $apiKEY, 'Content-Type:application/json'));
$response = json_decode(curl_exec($ch), true);
print_r($response);
?>

Make sure to update/replace the API KEY where appropriate. The above PHP code example returns a JSON structured like this:

{
    "data": [
        {
            "productType": "Edibles",
            "products": [
                {
                    "stateCode": "CO",
                    "locationId": "la111",
                    "sku": "bwc_gummies1",
                    "inventoryQuantity": "100",
                    "yourCost": "$3.99",
                    "productName": "Gummies #1",
                    "productDescription": "Long Description here",
                    "productImage": "https://s3-us-west-1.amazonaws.com/celebsncdn1/gummie1.png"
                },
                {
                    "stateCode": "CO",
                    "locationId": "la111",
                    "sku": "bwc_choc1",
                    "inventoryQuantity": "100",
                    "yourCost": "$4.99",
                    "productName": "Chocolate Edibles",
                    "productDescription": "Long Description here",
                    "productImage": "https://s3-us-west-1.amazonaws.com/celebsncdn1/chocolate.png"
                },
                {
                    "stateCode": "CO",
                    "locationId": "la111",
                    "sku": "bwc_gummies2",
                    "inventoryQuantity": "100",
                    "yourCost": "$5.99",
                    "productName": "Gummies #2",
                    "productDescription": "Long Description here",
                    "productImage": "https://s3-us-west-1.amazonaws.com/celebsncdn1/gummie2.png"
                }
            ]
        }
    ],
    "statusText": "OK",
    "statusCode": "200"
}

Make a GET call to /v1/catalogue to retrieve pricing information on our products.

HTTP Request

GET https://sandbox.togo420.com/v1/catalogue

Query Parameters

Parameter Type Description
x-merchant-id string Your MerchantID provided via the Developer Dashboard.
x-api-key string API Key provided via either the LIVE or Sandbox Developer Dashboards.
stateCode string Two-letter state code where the order will be delivered(optional). Otherwise a list of all our product pricing is returned.
skus array An array with SKUs of products to check(optional). Otherwise a list of all our product pricing is returned.

Errors

The API uses the following standard error codes:

Error Code Meaning
400 Bad Request -- Your request is invalid.
401 Unauthorized -- Your API key is wrong.
403 Forbidden -- This request is hidden for administrators only.
404 Not Found -- The specified item could not be found.
405 Method Not Allowed -- You tried to access a method with an invalid method.
406 Not Acceptable -- You requested a format that isn't json.
410 Gone -- The method requested has been removed from our servers.
429 Too Many Requests -- You're requesting too many requets! Slow down!
500 Internal Server Error -- We had a problem with our server. Try again later.
503 Service Unavailable -- We're temporarily offline for maintenance. Please try again later.
php