Posts Tagged ‘IContact API’

Using ConstantContact API and IContact API for Email Marketing in your application

Wednesday, January 7th, 2009

source : www.visionxpo.net

Last week, we got a requirement from one of our client of Yoga Management Software to integrate Email marketing service in their software. I had some research on it before getting into real thing and passing requirements to development team.

I believe there are two leading Email marketing companies

  • IContact.com
  • ConstantContact.com

I have personally used IContact.com and even we are developing clone of IContact.com

i.e www.emailerAMA.com

Coming back to topic, when it comes to integrating this service into your own application, i found IContact API more interesting, organized, well structured and secure but LESS DOCUMENTATION AND HELP in .NET

we had less time so i found it better to go for ConstantContact.com since we had less time and data was not that sensitive though i did not like their data security architecture.

without wasting time here is code snippet in VB.NET (sorry for not well formatted code as this is sample that i passed to my development team for help so as i am posting here)

Private Sub AddContact()
‘Setup your variables
Dim sUsername As String = “malikrizwan”
Dim sPassword As String = “123456″
Dim sUri As String = “http://api.constantcontact.com/ws/customers/” & sUsername & “/activities”
Dim sListUri As String = “http://api.constantcontact.com/ws/customers/” & sUsername & “/lists/1″ ‘If you have more than one list, change this number to whichever list you’re targeting
Dim sAPIKey As String = “371a3142-6267-4342-96e5-51ff1b951f06″

‘Setup an HttpWebRequest to send the data
Dim address As New Uri(sUri)
Dim request As HttpWebRequest = TryCast(WebRequest.Create(address), HttpWebRequest)
request.Credentials = New NetworkCredential((sAPIKey & “%” & sUsername), sPassword)
request.Method = “POST”
request.ContentType = “application/x-www-form-urlencoded”

‘Build an encoded string of the data to pass to Constant Contact
‘More info on this can be found at http://developer.constantcontact.com/doc/activities
Dim data As New StringBuilder()
data.Append(”activityType=” + MyUrlEncode(”SV_ADD”))
data.Append(”&data=” + MyUrlEncode((”Email Address,Email Type,First Name,Last Name,Company Name” & Chr(10))))
data.Append(MyUrlEncode((”youremail@yourserver.com,HTML,YourName,VisionXpo”)))
data.Append(”&lists=” + MyUrlEncode(sListUri))

‘The “guts” of the code to execute the request and return a response
‘The response (returned as ’strResponse’) will be XML.  You can parse this for status messages if you like, or just ignore it.
Dim byteData As Byte() = UTF8Encoding.UTF8.GetBytes(data.ToString())
Dim st As String = String.Empty

request.ContentLength = byteData.Length
Using postStream As Stream = request.GetRequestStream()
postStream.Write(byteData, 0, byteData.Length)
End Using

Using response As HttpWebResponse = TryCast(request.GetResponse(), HttpWebResponse)
Dim reader As New StreamReader(response.GetResponseStream())
st = reader.ReadToEnd()
End Using
End Sub

Public Function MyUrlEncode(ByVal str As String) As String
Dim sb As New StringBuilder()

For Each c As Char In str
If Char.IsLetterOrDigit(c) Then
sb.Append(c)
Else
sb.AppendFormat(”%{0:X02}”, CInt(Ascw(c)))
End If
Next
Return sb.ToString()
End Function