Jump to content

  •  

Photo

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


  • Please log in to reply
3 replies to this topic

#1 RobinDC  newbie

RobinDC
  • Members
  • 9 posts
  • FM Application:12 Advance
  • Platform:Mac OS X Lion
  • Skill Level:Expert
  • Certification:12
  • Membership:TechNet
  • Time Online: 1h 53m 31s

Posted 20 March 2013 - 11:48 PM

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 &nbsp;<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;
	}
	
?>

 

 


  • 0

#2 NutsToThis  newbie

NutsToThis
  • Newbies
  • PipPip
  • 2 posts
  • FM Application:12 Advance
  • Platform:Mac OS X Mavericks
  • Skill Level:Intermediate

Posted 08 July 2014 - 12:08 PM

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.


  • 0

#3 comment  consultant

comment
  • Members
  • 24,556 posts
  • Time Online: 344d 8h 20m 35s

Posted 08 July 2014 - 01:06 PM

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...34.html#1079151

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


  • 0

#4 NutsToThis  newbie

NutsToThis
  • Newbies
  • PipPip
  • 2 posts
  • FM Application:12 Advance
  • Platform:Mac OS X Mavericks
  • Skill Level:Intermediate

Posted 10 July 2014 - 11:34 AM

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.


  • 0




FMForum Advertisers