Jump to content

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


RobinDC

This topic is 3550 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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:[email protected]/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:[email protected]/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'>
		<form>
		<br /><br />" . htmlentities("Example - https://user:[email protected]/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;
	}
	
?>

 

 

Link to comment
Share on other sites

  • 1 year later...
  • Newbies

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,

Daren.

Link to comment
Share on other sites

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:

http://www.filemaker.com/help/13/fmp/en/html/non_toc.46.34.html#1079151

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

Link to comment
Share on other sites

This topic is 3550 days old. Please don't post here. Open a new topic instead.

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
×
×
  • Create New...

Important Information

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