Last active
September 18, 2021 15:54
-
-
Save sparkweb/10933839 to your computer and use it in GitHub Desktop.
Order Desk API: Order Methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Order Desk API: Get Order List | |
//To get your Store ID and API Key, go to Order Desk > Settings > Advanced | |
//Setup | |
$store_id = 0; | |
$api_key = ""; | |
//Setup Query | |
$args = array( | |
"limit" => 50, //max 500 | |
"offset" => 0, //starting record | |
"order_by" => "date_modified", | |
"order" => "desc", //desc or asc | |
//"email" => "[email protected]", //get orders for a particular email address | |
//"search_start_date" => "2015-01-01", //get all orders that were added at or on a particular time | |
//"search_end_date" => "2015-12-31 11:59:59", //get all orders that were added before a particular time | |
//"modified_start_date" => "2015-01-01", //get all orders that were modified at or on a particular time | |
//"modified_end_date" => "2015-12-31 11:59:59", //get all orders that were modified before a particular time | |
//"folder_id" => "1", //enter a folder id to search, multiple folders can be specified as "1,2,3" | |
); | |
//Setup cURL Variables | |
$url = "https://app.orderdesk.me/api/orders?" . http_build_query($args); | |
$headers = array( | |
"ORDERDESK-STORE-ID: {$store_id}", | |
"ORDERDESK-API-KEY: {$api_key}", | |
"Content-Type: application/json", | |
); | |
//Setup cURL | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 30); | |
//Send To Order Desk and Parse Response | |
$response = trim(curl_exec($ch)); | |
$info = curl_getinfo($ch); | |
$json = json_decode($response, 1); | |
//Not Valid JSON? | |
if (!is_array($json)) { | |
echo "<b>Non-JSON Return:</b><br>"; | |
echo $response; | |
} | |
//Show Response | |
echo "<b>Order Response:</b><br>"; | |
echo "<pre>" . print_r($json, 1) . "</pre>"; | |
//Show cuRL Connection Details | |
echo "<b>cURL Response:</b><br>"; | |
echo "<pre>" . print_r($info, 1) . "</pre>"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Order Desk API: Get Single Order | |
//To get your Store ID and API Key, go to Order Desk > Settings > Advanced | |
//Setup | |
$store_id = 0; | |
$api_key = ""; | |
//Setup Query | |
$order_id = 0; | |
//Setup cURL Variables | |
$url = "https://app.orderdesk.me/api/orders/" . $order_id; | |
$headers = array( | |
"ORDERDESK-STORE-ID: {$store_id}", | |
"ORDERDESK-API-KEY: {$api_key}", | |
"Content-Type: application/json", | |
); | |
//Setup cURL | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 30); | |
//Send To Order Desk and Parse Response | |
$response = trim(curl_exec($ch)); | |
$info = curl_getinfo($ch); | |
$json = json_decode($response, 1); | |
//Not Valid JSON? | |
if (!is_array($json)) { | |
echo "<b>Non-JSON Return:</b><br>"; | |
echo $response; | |
} | |
//Show Response | |
echo "<b>Order Response:</b><br>"; | |
echo "<pre>" . print_r($json, 1) . "</pre>"; | |
//Show cuRL Connection Details | |
echo "<b>cURL Response:</b><br>"; | |
echo "<pre>" . print_r($info, 1) . "</pre>"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Order Desk API: Insert New Order | |
//To get your Store ID and API Key, go to Order Desk > Settings > Advanced | |
//Setup | |
$store_id = 0; | |
$api_key = ""; | |
//Build Order Here | |
$order = array( | |
"source_id" => "", //Your Order Number, optional | |
"email" => "[email protected]", | |
"shipping_method" => "USPS Priority Mail", | |
"shipping_total" => 6.00, | |
"handling_total" => 1.50, | |
"tax_total" => 0, | |
"cc_number_masked" => "xxxx-xxxx-xxxx-1111", //Do Not Pass In Full Card Number | |
"cc_exp" => "01/2016", | |
"processor_response" => "Authorize.net Transaction ID: 1234567890", | |
"payment_type" => "Visa", | |
"payment_status" => "Approved", | |
"customer_id" => "", //Your internal customer ID | |
"ip_address" => "", //Customer's IP Address | |
"date_added" => "2013-10-14 01:01:01", //Order Date Must be in GMT | |
"discount_list" => array( | |
array( | |
"name" => "Discount 1", | |
"code" => "DUJJEDS4XC" | |
"amount" => 1.50, //Positive Numbers Will Subtract this Discount Amount From Total | |
), | |
array( | |
"name" => "Discount 2", | |
"code" => "KEJJ6XSW72" | |
"amount" => .25, | |
), | |
), | |
"shipping_first_name" => "John", | |
"shipping_last_name" => "Doe", | |
"shipping_company" => "", | |
"shipping_address1" => "123 Main St", | |
"shipping_address2" => "", | |
"shipping_address3" => "", | |
"shipping_address4" => "", | |
"shipping_city" => "Bluffton", | |
"shipping_state" => "MA", | |
"shipping_postal_code" => "55555", | |
"shipping_country" => "US", | |
"shipping_phone" => "555-555-5555", | |
"customer_first_name" => "John", | |
"customer_last_name" => "Doe", | |
"customer_company" => "", | |
"customer_address1" => "123 Main St", | |
"customer_address2" => "", | |
"customer_city" => "Bluffton", | |
"customer_state" => "MA", | |
"customer_postal_code" => "55555", | |
"customer_country" => "US", | |
"customer_phone" => "555-555-5555", | |
"order_items" => array( | |
array( | |
"code" => "4534534", | |
"name" => "Widget 1", | |
"price" => "10", | |
"quantity" => 1, | |
"delivery_type" => "ship", | |
"variation_list" = array( | |
"Size" => "Large", | |
"Color" => "Red", | |
), | |
"metadata" = array( | |
"Image URL" => "X", | |
), | |
), | |
array( | |
"code" => "809808", | |
"name" => "Widget 2", | |
"price" => "1", | |
"quantity" => 2, | |
"weight" => 1 | |
), | |
), | |
"checkout_data" => array( | |
"Newsletter" => "on", | |
), | |
"order_metadata" => array( | |
"Field 1" => "Value 1", | |
), | |
); | |
//Setup cURL Variables | |
$url = "https://app.orderdesk.me/api/orders"; | |
$order_content = json_encode($order); | |
$headers = array( | |
"ORDERDESK-STORE-ID: $store_id", | |
"ORDERDESK-API-KEY: $api_key", | |
"Content-Type: application/json", | |
"Content-Length: " . strlen($order_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, $order_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); | |
//Not Valid JSON? | |
if (!is_array($json)) { | |
echo "<b>Non-JSON Return:</b><br>"; | |
echo $response; | |
} | |
//Show Response | |
echo "<b>Order Response:</b><br>"; | |
echo "<pre>" . print_r($json, 1) . "</pre>"; | |
//Show cuRL Connection Details | |
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