Reply
Advisor
ShawnM641
Posts: 22
Registered: ‎12-01-2011
Accepted Solution

Retrieve LISTS associated with CAMPAIGN

I have successfully used the API to associate a LIST with a CAMPAIGN but when I retrieve the CAMPAIGN the CONTACTLISTS array is empty. Is there some other method of retrieving the LISTS associated with a CAMPAIGN?

Ryan_D
Posts: 453
Topics: 0
Kudos: 20
Solutions: 21
Registered: ‎06-28-2011

Re: Retrieve LISTS associated with CAMPAIGN

Hey,

 

Once you associate the list you should be able to pull the lists straight out of the Campaign.

 

 <ContactLists>
        <ContactList id="http://api.constantcontact.com/ws/customers/Username/lists/1">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/Username/lists/1" rel="self"></link>
        </ContactList>
        <ContactList id="http://api.constantcontact.com/ws/customers/Username/lists/9">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/Username/lists/9" rel="self"></link>
        </ContactList>
      </ContactLists>

 That is an actual response from my campaign in my account. Please supply your code and we can try to troubleshoot it for you.

Ryan Davis
Support Engineer, Constant Contact
Occasional Visitor
ShawnM948
Posts: 2
Registered: ‎12-19-2011

Re: Retrieve LISTS associated with CAMPAIGN

Digging deeper has revealed a failure in the supplied Coldfusion code. It does not carry the list of lists over from the response to the final structure. Working on fixing it and I'll send you the code snippet.

 

Advisor
ShawnM641
Posts: 22
Registered: ‎12-01-2011

Re: Retrieve LISTS associated with CAMPAIGN

Added the following to CampaignsCollection.createCampaignStruct()

 

Similar to code in ContactsCollection.createContactStruct(). This code is CF9 and above I believe, see the contacts example for a backwards compatible version if needed.

 

if(structKeyExists(local.tempStruct, "ContactLists"))

{

local.contactLists = [];

for(i=1; i <= arrayLen(local.tempStruct.ContactLists.ContactList); i++)

{

local.contactLists[i] = local.tempStruct.ContactLists.ContactList[i].xmlAttributes.id;

 }

local.campaign['contactLists'] = local.contactLists;

}

Advisor
ShawnM641
Posts: 22
Registered: ‎12-01-2011

Re: Retrieve LISTS associated with CAMPAIGN

Be sure and put those loop counters in local scope. Needs to be done elsewhere in the collection as well or they step on each other.

 

if(structKeyExists(local.tempStruct, "ContactLists"))

{

local.contactLists = [];

for(local.i=1; i <= arrayLen(local.tempStruct.ContactLists.ContactList); local.i++)

local.contactLists[local.i] = local.tempStruct.ContactLists.ContactList[local.i].xmlAttributes.id;

 

local.campaign['contactLists'] = local.contactLists;

}