Forked from sparkweb/api-returning-inventory-items.php
Created
July 24, 2016 18:20
-
-
Save mehulkaklotar/d05f8a1818e68a9c05295ec23242f808 to your computer and use it in GitHub Desktop.
Order Desk API: Get Inventory Items
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 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