Paul Alkema

Discussions on Web Development and Security

Paul Alkema

How to subscribe a user in Exact Target via their API

May 11, 2010 · 25 Comments

Since obviously the Exact Target community has no appreciation for the ColdFusion community, I feel that I should post the code that I wrote to subscribe a user to a list.

Here's my cfc...

<cfcomponent>
    <cffunction 
    	name="subscribeUser" 
        access="public" 
        returntype="string"
        hint="Subscribes a user to the specified list in Exact Target.">
        <cfargument 
        	name="company" 
            type="string" 
            required="yes"
             />
        <cfargument 
        	name="country" 
            type="string" 
            required="no" 
             />
        <cfargument 
        	name="emailAddress" 
            type="string" 
            required="yes"
             />
        <cfargument 
        	name="firstName" 
            type="string" 
            required="yes"
             />
        <cfargument 
        	name="lastName" 
            type="string" 
            required="yes"
             />
        <cfargument 
        	name="emailType"
            type="string" 
            required="yes"
             />
        <cfargument 
        	name="userid" 
            type="string" 
            required="yes" 
            default=""
             />
        <cfargument
        	 name="listId" 
             type="numeric" 
             required="no" 
             default="<listid>">
        <cfset var cfhttp = "">
        <cfhttp 
            url="http://cl.exct.net/subscribe.aspx?lid=#arguments.listId#" 
            method="post">
          <!--- company --->
          <cfhttpparam 
                name="COMPANY" 
                type="FormField" 
                value="#arguments.company#" 
                 />
          <!--- country --->
          <cfhttpparam 
                name="Country" 
                type="FormField" 
                value="#arguments.country#"
                 />
          <!--- email address --->
          <cfhttpparam
                name="email address" 
                type="FormField" 
                value="#arguments.emailAddress#"
                 />
          <!--- first name --->
          <cfhttpparam 
                name="FIRST NAME" 
                type="FormField" 
                value="#arguments.firstName#"
                 />
          <!--- last name --->
          <cfhttpparam 
                name="LAST NAME" 
                type="FormField" 
                value="#arguments.lastName#"
                 />
          <!--- email type --->
          <cfhttpparam 
                name="Email Type" 
                type="FormField" 
                value="#arguments.emailType#"
                 />
          <!--- user id --->
          <cfhttpparam 
                name="MID" 
                type="FormField" 
                value="#arguments.userId#"
                 />
          <!--- action --->
          <cfhttpparam 
                name="SUBACTION" 
                type="FormField" 
                value="sub_add_update"
                 />
        </cfhttp>
        <cfreturn cfhttp.FileContent />
    </cffunction>
</cfcomponent>

Here's my cfc invoke..

    <cfinvoke
        component="email-subscribe"
        method="subscribeUser"
        company="{user's company}"
        emailAddress="{user's email address}"
        firstName="{user's first name}"
        lastName="{user's last name}"
        country="{user's country}"
        emailType="{user's email type}"
        userid="{}"
        returnvariable="confirmation"
         />

The above CF code will add a user to the designated mailing list.

Tags: ColdFusion, Exact Target, ExactTarget, ColdFusion API, Paul Alkema

Tags: ColdFusion