Skip to content

Instantly share code, notes, and snippets.

@sparkweb
Last active July 24, 2016 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sparkweb/01fe36b5bba0de230a6b to your computer and use it in GitHub Desktop.
Save sparkweb/01fe36b5bba0de230a6b to your computer and use it in GitHub Desktop.
Order Desk API: Get Inventory Items
<?php
//Order Desk API: Get Inventory Items
//To get your Store ID and API Key, go to Order Desk > Settings > Advanced
//Setup
$store_id = 0;
$api_key = "";
//Setup cURL Variables
$url = "https://app.orderdesk.me/api/inventory_items";
$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>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment