The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

help listing email archive links using API

Highlighted
Occasional Contributor

help listing email archive links using API

I'm trying to avoid the manual process of adding campaigns that have been archived to an html page, and would rather generate a simple list of those campaigns that HAVE been archived.

 

I'm using the API to return a list of all SENT campaigns, then one by one checking for Archive status of Published, and if so, listing the Archive URL on the page.

This takes a very long time to load, even though it's only cycling through the first 50 emails. (of course, this is also problematic if we have archives that are older than the first 50 sent campaigns)

Is there any way to create that list automatically without cycling through every email sent out?

10 REPLIES 10
Highlighted
Employee

Re: help listing email archive links using API

Hey,

 

If you are using our new PHP wrapper you can do something like this to get you started.

 

$ConstantContact = new ConstantContact("basic", "apikey", "username", "password");

$SentCampaigns = $ConstantContact->getCampaignsByStatus("Sent");

?><table><?php
do {
	foreach($SentCampaigns['campaigns'] as $Campaign)
	{
		$myCampaign = $ConstantContact->getCampaigndetails($Campaign);
		if($myCampaign->archiveStatus == "Published")
		{
			?>
			<table>
			<tr>
			<td>
			<?php echo $myCampaign->name; ?>
			</td>
			<td>
			<?php echo $myCampaign->archiveUrl; ?>
			</td>
			</tr>
			<?php 
		}
	}
	if($ConstantContact->getCampaignsByStatus("Sent", $SentCampaigns['nextLink']) != FALSE)
	{
		$NextSet = $ConstantContact->getCampaignsByStatus("Sent", $SentCampaigns['nextLink']);
		$SentCampaigns = $NextSet;
	}
	
}while($SentCampaigns['nextLink']!= false);

?></table>

 Please let me know if this helps.

Ryan Davis
Quality Engineer
Highlighted
Occasional Contributor

Re: help listing email archive links using API

Ryan, That's almost exactly the code I am using - but I'm getting a 502 proxy error or timeout. I'm assuming the issue is with looping through getCampaignDetails too many times. Any suggestions?

Tags (1)
Highlighted
Moderator

Re: help listing email archive links using API

Are any of the requests going through or are all of them returning 502/timeout?  Also, can you provide us with the full error message being returned by us?  Our limits to API access are quite high and there isn't enough campaign content in your account for you to hit those limits even if you attempted to cycle through and pull all the campaigns.

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Occasional Contributor

Re: help listing email archive links using API

I sent you a PM with the code and link to the page it's on. Thank you!

Highlighted
Moderator

Re: help listing email archive links using API

Thanks for providing the URL and code.  This error message we're seeing is not usually related to actual PHP code or a server error but to an Apache Proxy server configuration error.  You'll notice that the error is being returned to a file on your server and not through something on Constant Contact side of the connection.  Also, the detailed error explains a lot into the underlying cause:

 

Proxy Error

The proxy server received an invalid response from an upstream server. The proxy server could not handle the request GET /enews/cc/campaign_archive.php/.

Reason: Error reading from remote server

 


Apache/2.2 Server at www.east91st.org Port 80
 
 
While I am not an expert on Apache or server configurations, this is likely caused by either the PHP script taking too long to run and running past the Apache server time out, thus causing an error since the upstream server could not send a response or there is a configuration issue in the proxy configuration you're using in Apache.  I've seen a few Apache forum posts saying that there is a known problem with versions of httpd prior to 2.2.4 causing these errors when proxy settings are included and also mentions of several people solving this problem by adjusting the timeout settings to a longer timeout wait.  If the script itself takes too long to run, which is possibly if you're looking at a large number of campaigns and making a large number of serial requests instead of parallel requests, this is likely the root cause.
 
We're going to run your code locally today to ensure that it does work and will post additional information later today to confirm that the code is indeed correct.
Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Occasional Participant

Re: help listing email archive links using API

can anybody show me an example of this in Javascript?

 

Highlighted
Occasional Participant

Re: help listing email archive links using API

can this be done in javascript?

Highlighted
Honored Contributor

Re: help listing email archive links using API

Hello,

 

At present it is not possible to integrate with the Constant Contact API in pure javascript. This is because ou API is not compatible with JSONP(Which only supports GET requests) and does not currently support CORS. Given this, the only way to use javascript without being blocked by XSS restrictions is to have a mechanism to forward your requests through a back-end script running on the same host. 

 

Please let me knwo if you have any questions!

 

Sincerely,

Elijah G.
API Support Engineer
Highlighted
Occasional Contributor

Re: help listing email archive links using API

I am building a PhoneGap app thats why i need it in jQuery / javascript

 

I guess I'll have to use wordpress to display the archive, do you have a more complete code that i can use in wordpress?

Developer Portal

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

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured