We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

Basic adding/subtracting single contacts with Coldfusion?

cfauthority
Participant

Basic adding/subtracting single contacts with Coldfusion?

I have been hired to work on a Coldfusion website and one of the "bonus" features they would like to have added is the adding of an e-mail address and first/last name directly to their Constant Contact account upon registration or removed in the online profile. Are there any examples of this implementation located here anywhere.

Any help is much appreciated.

Thank you!
11 REPLIES 11
DaveBerard
Moderator

We currently do not have any examples of Coldfusion provided by Constant Contact. It may be possible another developer has already done this before though and can provide you with some examples.
Dave Berard
Senior Product Manager, Constant Contact
bookbrowse
Occasional Participant

We're looking for the same thing too....
brownshoes
Regular Participant

This would be a really BIG help. Still no coldfusion samples?


Thanks,


-BS

mross6
Participant

Wow. This took me the better part of a day, but I finally figured out how to view contacts, view lists and bulk add contacts with Coldfusion.  Here's my very simple and "testing" code. It should get you started. Let me know if you have questions.


-Mark


<code>


&lt;cfset ccUsername = "username"&gt;

&lt;cfset ccPassword = "password"&gt;

&lt;cfset apikey = "12345"&gt;



&lt;!--- View Contacts ---&gt;

&lt;cfhttp url="https://api.constantcontact.com/ws/customers/#ccUsername#/contacts" method="get" username="#apikey#%#ccUsername#" password="#ccPassword#"&gt;

&lt;/cfhttp&gt;



&lt;cfoutput&gt;

&lt;xmp&gt;

#cfhttp.filecontent#

&lt;/xmp&gt;

&lt;/cfoutput&gt;



&lt;!--- View Lists ---&gt;

&lt;cfhttp url="https://api.constantcontact.com/ws/customers/#ccUsername#/lists" method="get" username="#apikey#%#ccUsername#" password="#ccPassword#"&gt;

&lt;/cfhttp&gt;



&lt;cfoutput&gt;

&lt;xmp&gt;

#cfhttp.filecontent#

&lt;/xmp&gt;

&lt;/cfoutput&gt;





&lt;!--- Update Contacts in Batch ---&gt;

&lt;cfset ccData = "name,email

test one,one@test.com

test two,two@test.com"&gt;

&lt;cfset ccLists = "http://api.constantcontact.com/ws/customers/#ccUsername#/lists/1"&gt;



&lt;cfset ccBody = "activityType=SV_ADD&data=#URLEncodedFormat(ccData)#&lists=#URLEncodedFormat(ccLists)#"&gt;



&lt;cfhttp url="https://api.constantcontact.com/ws/customers/#ccUsername#/activities" method="post" username="#apikey#%#ccUsername#" password="#ccPassword#"&gt;

    &lt;cfhttpparam type="header" name="Content-type" value="application/x-www-form-urlencoded" /&gt;

    &lt;cfhttpparam value="#ccBody#" type="body" /&gt;

&lt;/cfhttp&gt;



&lt;cfoutput&gt;

#cfhttp.filecontent#&lt;br&gt;&lt;br&gt;

&lt;/cfoutput&gt;



</code>

brownshoes
Regular Participant

Thanks so much. That is a big help!!

gaviinternational
Participant

I downloaded the ColdFusion examples from CC but they do not work out of the box.


I gave up on fixing them and tried Google search, and found this. Just what I need - excellent!


Thanks a lot!


 


p.p. One suggestion to CC. Please, post some simple examples like the one above - few lines and excelent results, not tons of code. Very simple so even if our server environment is different they still work.


The examples that you have, don't work here and the error is 401 Basic Auth Failed, despite the fact that I am providing all my credential in a proper manner.

David_J
Employee

I have not received reports from anyone else that any of the ColdFusion samples are broken right out of the box, or that people receive 401 Authentication errors, provided that you are running ColdFusion9.  If you could provide some more information as to exactly what was not working, I'd be more than happy to take a look at them. The only thing that should need to be configured would be setting up the username, password and apikey in Application.cfc.


 


For example, in the ColdFusion library you would setup the username, password, and apikey in Application.cfc. Then you could make a 'development.cfm' (or any .cfm page) and use the following to display the first page of contacts.


<cfset contacts = new ContactsCollection().getContacts()>



<cfdump var="#contacts#">

David J

lpp_dev
Occasional Participant

This looks like a great solution but I am receiving this error:



Invalid xml declaration.

 Line: 3 Character: 3


<?xml version="1.0" encoding="UTF-8"?>



I converted all of the &lt; to < and all of the &gt; to >


Is it possible I need to convert other text as well?


Thanks!


John

lpp_dev
Occasional Participant

For me this cf code returned a blank page with the error I mentioned above.  So I looked at the source for my "blank" page and discovered the xml for all my contacts.  So the cf code seems to be correctly connecting to my account but is the cf supposed to parse this xml, or is the xml supposed to display in the browser?


Also, why is it saying that "<?xml version="1.0" encoding="UTF-8"?>" is an invalid xml declaration?


Thanks for reading this!


John

David_J
Employee

Contacts.getContacts() should be returning a multidimensional array of up to 50 contact objects, and a link to the next page of 50 if one exists. You should not be seeing XML at all. Would you be able to either post the code you are using here, or email your code (and username/password if you want me to test your specific account) to our webservices support team so that I can take

David J

lpp_dev
Occasional Participant

I have sent the cfm I am using to the webservices support team


Thanks!


John

Developer Portal

View API documentation, code samples, get your API key.

Visit Page