Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mehulkaklotar/f8ed7576dea1412d8dfe38be6f159ecc to your computer and use it in GitHub Desktop.
Save mehulkaklotar/f8ed7576dea1412d8dfe38be6f159ecc to your computer and use it in GitHub Desktop.
Order Desk API: Adding Shipments
<?php
//Order Desk API: Insert New Shipments
//To get your Store ID and API Key, go to Order Desk > Settings > Advanced
//Setup
$store_id = 0;
$api_key = "";
//Build Shipment Here
$new_shipments = array(
"order_id" => "24138", //This is the internal Order Desk ID
"shipments" => array(),
);
//You can also pass in the source ID and source name Lookup
/*
$new_shipments = array(
"source_id" => "272451031", //The external source ID
"source_name" => "FoxyCart", //The name of the external source
"shipments" => array(),
);
*/
//Now Add A Shipment
//Note that if the extra data fields aren't passed in, Order Desk will try to determine the carrier code
//If the code can be determined, Order Desk will attempt to create a tracking URL as well
$new_shipments['shipments'][] = array(
"tracking_number" => "1Z999AA10123456784",
);
//Alternate By Passing in More Data
/*
$new_shipments['shipments'][] = array(
"tracking_number" => "1Z999AA10123463921",
"carrier_code" => "UPS",
"shipment_method" => "UPS Ground",
"weight" => "1.0",
"tracking_url" => "http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=1Z999AA10123463921",
"date_shipped" => "2014-01-01",
);
*/
//Add as many shipments as you'd like
//$new_shipments['shipments'][] = array("tracking_number" => "1Z999AA10123456785");
//$new_shipments['shipments'][] = array("tracking_number" => "1Z999AA10123456786");
//$new_shipments['shipments'][] = array("tracking_number" => "1Z999AA10123456787");
//Setup cURL Variables
$url = "https://app.orderdesk.me/api/shipments";
$post_content = json_encode($new_shipments);
$headers = array(
"ORDERDESK-STORE-ID: $store_id",
"ORDERDESK-API-KEY: $api_key",
'Content-Type: application/json',
'Content-Length: ' . strlen($post_content),
);
//Setup cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_content);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
//Send To Order Desk and Parse Response
$response = trim(curl_exec($ch));
$info = curl_getinfo($ch);
$json = json_decode($response, 1);
echo "<b>Order Response:</b><br>";
echo "<pre>" . print_r($json, 1) . "</pre>";
echo "<b>cURL Response:</b><br>";
echo "<pre>" . print_r($info, 1) . "</pre>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment