v3 API contacts pagination

SarahA042
Rookie

How to handle /contacts pagination in v3 API,

there is no specification for it in the documentation,

I can only retrieve first 500 contacts of a list

1 REPLY 1
Courtney_E
Employee
0 Votes

Hello SarahA042,

 

Thank you for reaching out to Constant Contact API Developer Support. My team is here to assist outside software developers with questions about building into Constant Contact's API.

 

If your response for GET /contacts has over 500 results, at the bottom of the response body there will be a link you can make a GET call to for viewing the next 500 results, and if there are more results after that, there will be another link in the next response body, and so on:

 

{

  "contacts": [   …  ],

      "list_memberships": [   …   ],

    }

  ],

  "contacts_count": 3249,

  "_links": {

    "next": {

      "href": ""href": "/v3/contacts?cursor=/04fe9a97-a579-43c5-bb1a-58ed29bf0a6a"

    }

  },

  "status": "processing"

}

 

*You can view an example Response Sample in the upper right of the GET Contacts Collection section of our API Reference tester page:

https://v3.developer.constantcontact.com/api_reference/index.html#!/Contacts/getContacts

 

So, for the above link to the next page of results, you would make a GET call to:

https://api.cc.email/v3/contacts?cursor=/v3/activities/04fe9a97-a579-43c5-bb1a-58ed29bf0a6a

 

Then, if the response also has a value for  "_links": "next", then you’d make another call to that link until you reach the final results page, which will be indicated by not having a "_links": "next" value. 

 

You should be able to set up a variable within your program for if there is a  "_links": "next" value in your response body, and then have it make the additional GET call with the provided URL and append the response data. 

 

Alternatively, if you are just wanting to view  your contacts in one response file, you can use our Bulk Activities endpoint for Exporting Contacts to a File by making a POST call to /activities/contact_exports. This endpoint works similarly to when you export contacts from the website UI; it will not export deleted contacts, only those visible within the Contacts tab of your account. The export is formatted as a .csv file and the entries do not include Contact IDs.

 

Bulk Activities endpoint - Export Contacts to a File

https://v3.developer.constantcontact.com/api_reference/index.html#!/Bulk_Activities/postContactsExpo...

 

Response body example:

 "_links": {

    "self": {

      "href": "/v3/activities/04fe9a97-a579-43c5-bb1a-58ed29bf0a6a"

    },

    "results": {

      "href": "/v3/contacts_exports/04fe9a97-a579-43c5-bb1a-58ed29bf0a6a"

    }

 

In the "_links" section of the response body, you can make a GET call to the URL value for "self": "href" to see if the activity is completed: 

 

Example Request URL:

GET https://api.cc.email/v3/activities//v3/activities/04fe9a97-a579-43c5-bb1a-58ed29bf0a6a

 

GET an Activity Status
https://v3.developer.constantcontact.com/api_reference/index.html#!/Bulk_Activities/getActivity

 

Then, if the "state" value shows as "completed" in the response body of this call, you can make a GET call the URL value in "_links" that shows for "results":"href":

 

Example Request URL:

https://api.cc.email/v3/contact_exports/04fe9a97-a579-43c5-bb1a-58ed29bf0a6a

 

You can then download the .csv file, or have your program parse the data.

 

Please have a look and let us know if you have any other questions!


Regards,

Courtney E.
Tier II API Support Engineer

Did I answer your question?
If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
Resources
Developer Portal

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

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up