Jump to content
Sign in to follow this  

Sample BigCommerce PHP cURL code to update order status with XML response

Recommended Posts

RobinDC    0

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.


	// 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 &nbsp;<input type='text' name='data' style='width: 50%'> 
		<INPUT type='submit' value='Put to Update'>
		<br /><br />" . htmlentities("Example - https://user:apikey@example.com/api/v2/orders/100?<order><status_id>10</status_id></order>") . "
	} 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;



Share this post

Link to post
Share on other sites
NutsToThis    0

Hello all!


I'm trying to find a way into the whole Filemaker API world for the first time. I'm an experienced Filemaker developer but have only ever worked with self-contained databases.


I now have a customer with a BigCommerce store who wants their orders automatically added to their Filemaker order system, and other than exporting CSVs I haven't a clue where to start!


I keep reading about accessing PHP APIs using functions in Filemaker but I haven't got the grounding to be able to put things like this suggested solution into practice. I've spent days trawling Google for some kind of Idiots Guide to Working With APIs but no-one seems to write things like this. Are you guys just born with the know-how or something?!


Can somebody tell me what I need to know to get started with all this please??


Enormous thanks in anticipation,


Share this post

Link to post
Share on other sites
comment    1,390

I am puzzled regarding what your question actually is. It seems to me that if you want to import orders from BigCommerce to Filemaker (if that's what you're after), then you need "to find a way into the whole BigCommerce API world" - rather than Filemaker API.


With regard to the Filemaker end of this process, I suggest you have a look at:


Note that some of the options are new to v.13.

Share this post

Link to post
Share on other sites
NutsToThis    0

There you go - I'm so confused I don't even know what I'm asking for!


Anyway, thanks for the pointers. I think I've got a handle on which bit does what now.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Who Viewed the Topic

    1 member has viewed this topic:
    bac mac 

Important Information

By using this site, you agree to our Terms of Use.