Infusionsoft and SQL Server integration via C#.net

Infusionsoft

As per client requirement we have a tough task to use a .net API of Infusionsoft and fetch the customers information from the SQL Server Database they have. The task was tough as there is not much support available online for a .net API of Infusionsoft. But however we have successfully build a console application which fetches the required fields from the SQL Server database and creates a new customer into infusionsoft.

Here is the sample code used to fetch data.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using CookComputing.XmlRpc;
using CookComputing;
using InfusionSoftDotNet;
using System.Data.SqlClient;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SqlConnection con = new SqlConnection(Properties.Settings.Default.ConnectionString);

SqlCommand cmd = new SqlCommand(“Query String Here”, con);

SqlDataReader reader;

con.Open();

reader = cmd.ExecuteReader();

while (reader.Read())
{
XmlRpcStruct cid = new XmlRpcStruct();
cid.Add(“_CustomerID”, Convert.ToInt32(reader[“CustomerID”]));

string resultsString = string.Empty;
string[] selectedFields = { “Id” };

XmlRpcStruct[] results = isdnAPI.dsQuery(“Contact”, 1, 0, cid, selectedFields);

if (results.Length > 0)
{
int Id = Convert.ToInt32(results[0][“Id”]);
XmlRpcStruct conDat = new XmlRpcStruct();
conDat.Add(“FirstName”, reader[“FirstName”].ToString());
conDat.Add(“LastName”, reader[“LastName”].ToString());
conDat.Add(“StreetAddress1”, reader[“Address1”].ToString());
conDat.Add(“StreetAddress2”, reader[“Address2”].ToString());
conDat.Add(“City”, reader[“City”].ToString());
conDat.Add(“State”, reader[“StateOrProvince”].ToString());
conDat.Add(“PostalCode”, reader[“PostalCode”].ToString());

isdnAPI.dsUpdate(“Contact”, Id, conDat);           //dsUpdate function used for updating already exsisting data in Infusionsoft
}

else
{
XmlRpcStruct conDat = new XmlRpcStruct();
conDat.Add(“_CustomerID”, reader[“CustomerID”].ToString());
conDat.Add(“FirstName”, reader[“FirstName”].ToString());
conDat.Add(“LastName”, reader[“LastName”].ToString());
conDat.Add(“StreetAddress1”, reader[“Address1”].ToString());
conDat.Add(“StreetAddress2”, reader[“Address2”].ToString());
conDat.Add(“City”, reader[“City”].ToString());
conDat.Add(“State”, reader[“StateOrProvince”].ToString());
conDat.Add(“PostalCode”, reader[“PostalCode”].ToString());

isdnAPI.add(conDat);        // “add” is the function which is used to enter new data in Infusionsoft
}
}
reader.Close();
reader.Dispose();
con.Close();
}
}
}