403 forbidden error when trying to get more than 50 campaigns

Highlighted
Retail

403 forbidden error when trying to get more than 50 campaigns

So I am trying to get all the sent campaigns linked to my account using php. I have worked out getting the max of 50 per page. I recently added code to use the next_link and get all of them. I am not getting a forbidden 403 error. I have looked all over and found nothing helpful. Got any ideas?

 

 

Here is the code im am using :

 

 

$client = new ConstantContact("APIKEY");
$campaigns = array();
$params = array('status' => "SENT");
$count = 0;

while (true) {

$results = $client->emailMarketingService->getCampaigns("ACCESS_TOKEN",array(),$params);

if(empty($results->results))
{
break;
}

$campaigns = array_merge($campaigns,$results->results);

if(!$results->next){
break;
}

$params = $results->next;
}

pr($results);

 

Any help would be appreciated.

 

Thanks

1 REPLY 1
Highlighted
Honored Contributor

Re: 403 forbidden error when trying to get more than 50 campaigns

Hello,

 

After looking at your code, what's most likely happening is that because the next link isn't quite being set properly, it is interfering with how the API key is provided. This would in turn cause the API respond with a 403 error because it does not recognize the API key.

 

The best way to resolve this is to make a minor adjustment to how you're implementing the pagination. The correct method would be to assign params as follows:

$params = array('next' => $results->next);

If you're still having trouble after making this change, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer
Developer Portal

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

Visit Page

Register for our "Making Sense of Online Marketing for Retail" Webinar

Join us on Thursday, August 13th at 2pm ET for a free webinar where we'll discuss how to incorporate online marketing into your retail store.

Read More
Featured