Retrieve Contact List Id from Email Campaign

SOLVED
Highlighted
Occasional Contributor

Retrieve Contact List Id from Email Campaign

Hello Constant Contact Support,

 

We are using Java based Constant Contact API to accomplish member synch, bounced email managment and unsubscribe email address management.  Currently we are required to pull contact list id from email campaign.  Below I have presented the high level code that is written to accomplish the same:

 

// Create Constant Contact object
ConstantContact objConstantContact = new ConstantContact(strAPIKey, strAccessToken);

// Get all email campgaigns for the account
lsEmailCampaignResponse = objConstantContact.getAllEmailCampaigns();

if(lsEmailCampaignResponse != null)
{
iSize1 = lsEmailCampaignResponse.size();
}

for(int i=0; i < iSize1; i++)
{
// Get EmailCampaignResponse object
objEmailCampaignResponse = lsEmailCampaignResponse.get(i);

// Get Contact List
lsSentToContactList = objEmailCampaignResponse.getSentToContactLists();

System.out.println("Size of contact list = "+ lsSentToContactList.size());

for(int k = 0; k < lsSentToContactList.size(); k++)
{
System.out.println("Campaign Id ---->" + objEmailCampaignResponse.getId());
System.out.println("Contact List Id ---->" + lsSentToContactList.get(k).getId());
}

}

 

However the above mentioned code is not working.  We are unable to retrieve the contact list from the email campaign.  The highlighted line in the code above shows zero for all the campaigns that were tested so far.  However in reality the tested campgaigns are associated with atleast one contact list.  In that case why isn't the code mentioned above printing the contact list id?  Can you please look into this issue and reply at your earliest?

 

Thanks & Regards,

Srinivas.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Honored Contributor

Re: Retrieve Contact List Id from Email Campaign

Hello Srivanas,

 

After reviewing your issue, I believe that the source of your trouble has to do with how you are getting the information for each campaign. The code in the Java wapper to fetch a list of campaigns accesses an API endpoint which only returns basic data for each campaign. In order to get specific data such as the lists it was sent to for each campaign, you would need to fetch the detailed information for each campaign from the API. Here is a change to your code that demonstrates the basic idea of how this would be done:

 

// Get EmailCampaignResponse object
objEmailCampaignResponse = lsEmailCampaignResponse.get(i)
// Use the ID of the campaign to fetch the full details
objEmailCampaignResponse = objConstantContact.getEmailCampaign(objEmailCampaignResponse.getId());

If you are still running into issues once you've adapted the code to fetch the full details for the campaigns rather than only the basic data, please let us know and we will be happy to assist you further!

 

Best Regards,

Elijah G.
API Support Engineer

View solution in original post

3 REPLIES 3
Highlighted
Occasional Contributor

Re: Retrieve Contact List Id from Email Campaign

Hello Support,

 

Any answer / update for the question that I had posted yesterday?

Highlighted
Honored Contributor

Re: Retrieve Contact List Id from Email Campaign

Hello Srivanas,

 

After reviewing your issue, I believe that the source of your trouble has to do with how you are getting the information for each campaign. The code in the Java wapper to fetch a list of campaigns accesses an API endpoint which only returns basic data for each campaign. In order to get specific data such as the lists it was sent to for each campaign, you would need to fetch the detailed information for each campaign from the API. Here is a change to your code that demonstrates the basic idea of how this would be done:

 

// Get EmailCampaignResponse object
objEmailCampaignResponse = lsEmailCampaignResponse.get(i)
// Use the ID of the campaign to fetch the full details
objEmailCampaignResponse = objConstantContact.getEmailCampaign(objEmailCampaignResponse.getId());

If you are still running into issues once you've adapted the code to fetch the full details for the campaigns rather than only the basic data, please let us know and we will be happy to assist you further!

 

Best Regards,

Elijah G.
API Support Engineer

View solution in original post

Highlighted
Occasional Contributor

Re: Retrieve Contact List Id from Email Campaign

Hi Dave,

Thanks for the solution.  It worked great.  I am able to get the list id associated with campaign now.

 

Regards,

Srinivas

Developer Portal

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

Visit Page

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured