My God! This took me ages to figure out, alas, my ColdFusion app is now very smoothly interfacing with the Infusionsoft api. I'm sure to a lot of you, this is so easy that you would never think to post about it, but in my searches I found a LOT of other CF developers confused about how to do this, seemingly without resolution. Weary CF Googlers, may your infusionsoft/CF searches end here. Of course, like most things this turned out to be VERY simple, but without having any clue where to begin, it was agonizing.
[TO SEE THE SAMPLE AND SKIP THE INSTRUCTION, JUMP TO THE BOTTOM]
********** THE GOAL **********
A client of mine wants their website sign-up process to insert the contact information collected by the sign-up form into their Infusionsoft contact list. After it has been inserted into the contact list, they either want to add that contact to a group, or tag it.
********** THE PROBLEM *******
To my dismay, although the infusionsoft API instructions (http://developers.infusionsoft.com/wiki/index.php/Main_Page) have sample links for php, .net (c# and vb), java, and ColdFusion, the ColdFusion Samples read: "We need a Cold Fusion Sample to place here." Ugh. Not the first time I've seen that. Um, yeah, all of the other sample links had actual samples, but nones for CF... That will change very soon.
********** THE SOLUTION ******
For my example, I'm going to use the ContactService.add method, however you could use this same solution with any InfusionSoft API method as long as you use the proper name/value params.
Step 1 - Write up your XMLRPC structure or download XMLRPC.CFC, which will allow you to convert an array to XMLRPC. http://support.journurl.com/users/admin/index.cfm?mode=article&entry=938.
Step 2 - Create an array. The first value of the array will be the InfusionSoft API method name you are calling (ie. "ContactService.add"). The second value of the array will be a struct containing the contact params. Since we are dealing with XML here, its best to assign your struct values like "<cfset myStruct["FieldName"] = ''>" as opposed to "<cfset mystruct.FieldName=''>", as the latter will clobber your case sensitivity.
Step 3 - Convert your array to XMLRPC using XMLRPC.cfc
Step 4 - Make the call to the Infusionsoft API:
Step 5 - Convert myResult to CMFL using XMLRPC.cfc
<!--- XMLRPC.CFC can be downloaded at: http://support.journurl.com/users/admin/index.cfm?mode=article&entry=938 --->
<cfobject component="xmlrpc" name="cfc.xmlrpc">
<cfset myArray = ArrayNew(1)>
<!--- The method name --->
<cfset myArray = 'ContactService.add'>
<!--- Your Infusionsoft API Key --->
<cfset myArray = '13643d3c8910057ce07623ed01bb22b2'>
<!--- Setup the contact data --->
<cfset contactData["Email"]='[hidden email]'>
<!--- Add the contactData struct to the array --->
<cfset myArray = contactData>
<!--- Convert the CFML array to XMLRPC --->
<cfset xmlString = cfc.xmlrpc.CFML2XMLRPC(myArray)>
<cfhttp method="post" url="https://mach2.infusionsoft.com/api/xmlrpc" result="myResult" >
<cfhttpparam type="xml" value="#xmlString#">
<!--- Convert the result from XMLRPC to CFML --->
<cfset myCFMLResult = cfc.xmlrpc.XMLRPC2CFML(myResult.fileContent)>
<!--- ENJOY A DELICIOUS GLASS OF CHAMPAGNE--->
Order the Adobe Coldfusion Anthology now!
|Free forum by Nabble||Edit this page|