Hello all - I'm new to APIs but I haven't been able to figure out this problem.
I need to get a comprehensive list of all the campaign_ids associated with my account. The Email Campaign Collections GET is perfect, except it maxes out at 50 per page. I've looked over the documentation for Paginated Output in the hopes of figuring out how to get to the "next page" (next_link) of results, but I keep getting errors.
The initial Pagination Output example (https//:api.constantcontact.com/v2/contacts?limit=25&api_key=<api_key>) needs to be modified to include the access_token in order to show the results in-browser (https://api.constantcontact.com/v2/emailmarketing/campaigns?limit=50&api_key=<api_key>&access_token=...
This works well and provides me with the next_link URL. This led me to the next Pagination Output example (https//:api.constantcontact.com/v2/contacts?api_key=<api_key>&next=<next_link>). I've tried all possible variations that I can think of (<api_key>&<access_token>&<next_link>, <next_link>&<api_key>&<access_token>, etc.) but they all create an error message. I've removed the <access_token> so as to reflect the exact Pagination Output example, but then I get an authorization error (presumably because I didn't include the <access_token>.
The only relevant posts that I've found were The Mashery account associated with this request is not active, or an invalid API and ContactsCollection pagination.
The ultimate goal for this project is to download all of the email campaign history (send date, email campaign name, email campaign, ID, open/click/etc.) for every person in Contant Contacts. This information is housed in every profile but I don't want to download all 7800+ people across 270+ email campaigns. My current "plan of attack" has me getting a list of the campaign_ids (see above), then the Email Campaign Tracking methods for sends/open/etc. for each campaign.
If anyone has any thoughts on how to best solve the problem OR achieve the ultimate goal that would be greatly appreciated. Thank you.
Solved! Go to Solution.
Based on what you've described, the best solution is to use some form of HTTP client other than a vanilla browser that will allow you to attach headers to your reuqests. This is because the preferred method for including the access tokens is to include the following header on each request:
Authorization: Bearer <TOKEN>
However, after a bit of testing on this personally I was able to use the pagination normally even including the access token in the URL. One thing that does stand out about the examples that you provided is that for some of your examples you are calling /v2/contacts and for others it is /v2/emailmarketing/campaigns. It is very important to note that a next link for the campaigns collection will not work for the contacts collection, and vice versa.
Here's an example of how I tested this:
https://api.constantcontact.com/v2/emailmarketing/campaigns?api_key=<APIKEY>&access_token=<TOKEN> Which gave me the next link of "cGFnZU51bT0yJnBhZ2VTaXplPTUw". I then used the following URL to get the next page: https://api.constantcontact.com/v2/emailmarketing/campaigns?next=cGFnZU51bT0yJnBhZ2VTaXplPTUw&api_key=<APIKEY>&access_token=<TOKEN>
If you have any questions, please let me know!