Hopefully, this post will help someone trying to integrate their solution with the BigCommerce API. FileMaker can update the status of an order on BigCommerce by sending a URL to this PHP, transforming a GET call URL to a PUT call for the BigCommerce API v2. The file is hosted on an internal server for security, and requires the cURL library. The key is the curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT"); line to change the normal POST process for adding data into a PUT process for changing data.
<?php
// Converts a GET encoded URL to PUT for BigCommerce API v2. -Rob Caldwell 3/2013
// Requires cURL library for PHP on the server.
// Strongly recommend loading this file on a private internal server for data security.
// Sample update calculation for FileMaker v10-12 = $php_file_location & "?data=" & Substitute ( GetAsURLEncoded ( "https://user:apikey@example.com/api/v2/orders/" & $web_order_id & "?<order><status_id>" & $new_order_status & "</status_id></order>" ) ; [ ":" ; "%3A" ] )
// XML response can be imported directly into FileMaker using an XML stylesheet (XSLT) like the one included in the examples with FileMaker software.
//
// You can check any existing order with this simple URL format:
// "https://user:apikey@example.com/api/v2/orders/" & $web_order_id
/* Authentication not needed if they are included in the url.
$credentials = "user:apikey";*/
$headers = array(
"Content-type: application/xml",
//"Authorization: Basic " . base64_encode($credentials)
);
$uri = isset($_GET['data']) ? $_GET['data'] : '' ;
if ($uri == "") {
echo "<html><head><title>Get to Put</title></head><body>
<div style='text-align:center; padding: 50px 0px;'>
<form method='get'>
URL <input type='text' name='data' style='width: 50%'>
<INPUT type='submit' value='Put to Update'>
<form>
<br /><br />" . htmlentities("Example - https://user:apikey@example.com/api/v2/orders/100?<order><status_id>10</status_id></order>") . "
</div>
</body></html>";
} else {
// Get the current url and split it at the '?'
$postArray = explode("?", $uri);
$url = $postArray[0];
$args = $postArray[1];
$ch = curl_init($url); //open connection
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //optional, sends response to a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 60); //set to 60 seconds from BC API Guide v1 PDF example
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //load all header data
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); //comment out this PUT line to change to a POST statement
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$result = curl_exec($ch); //execute post
curl_close($ch); //close connection
// Quick and dirty output check - if result is XML, make it render nicely in browser
if (strstr($result, "<?xml") && !strstr($result, "<error>")) header ("content-type: text/xml");
echo $result;
//echo $uri;
}
?>