Although it has been years since I have worked in classic ASP, I recently addressed a question on the Infusionsoft Developer Forum in which the original poster referred to me as a genius for solving his problem. How could I not create an entire blog from that single comment?
Below is a sample of the ASP code required to create a contact. This example uses VBScript and assumes that the ASP XML-RPC library is already installed on the web server.
[sourcecode language=”vb”]
<!–#include virtual="/aspxmlrpc/code/xmlrpc.asp" –>
<%
Dim key, url, contact, contactId
Dim contactParamList, optinParamList
‘key is the encrypted API key you got from Infusionsoft
key = "theKey"
‘URL is the API Url you got from Infusionsoft
url = "https://theApp.infusionsoft.com:443/api/xmlrpc"
‘Scripting.Dictionary used to represent XML-RPC struct
Set contact = Server.CreateObject("Scripting.Dictionary")
contact.Add "FirstName", "Barney"
contact.Add "LastName", "Fife"
contact.Add "Email", "barney.fife@wamley.com"
contact.Add "DateCreated", Date
‘contactParamList will hold parameters to the service call
ReDim contactParamList(2)
contactParamList(0) = key
Set contactParamList(1) = contact
‘Make the API call. The result is the ID of the new contact
contactId = xmlRPC (url, "ContactService.add", contactParamList)
‘Clean up and print results
Set contact = Nothing
ReDim optinParamList(3)
optinParamList(0) = key
optinParamList(1) = "barney.fife@wamley.com"
optinParamList(2) = "Opted in through API"
‘Call method from xmlrpc.asp include file
xmlRPC url, "APIEmailService.optIn", optinParamList
%>
[/sourcecode]
The Infusionsoft API has five services that allow developers to request or post information. The two services that I have used for this example are the Contact Service and the APIEmailService.
The ContactService.add
method will add a contact to your application, which essentially has the same affect as the DataService.add
method with the only exception being the execution of a configurable Action Set that is executed when a contact is added.
Another point to note is the final API call to APIEmailService.optIn
method. This call is not required when creating a new contact, as the ContactService.add
method will automatically single opt-in a user. If on the other hand, we were to have updated that email address for a contact with the ContactService.update
method, the email address would need to have the APIEmailService.optIn
method run.
Links to the XML-RPC libraries can be found on the Resources page.