- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to pull data via the api in-order to import it into a database ( FileMaker to be specific ). I am having a probem following pagination and the next links in-order to get all of our data. I am trying to use Python and the requests module to get this data, but when I try to get the value of ['next_link'] in python I keep getting a KeyError. I am not married to Python, in fact I know very very little, however, it works with filemaker, and so far I can get the first page of any query, I am just not able to follow the next links. Does anyone, or is anyone willing to share how they follow pagination in a script?
Thanks!!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
It's possible that you might not be going far enough into the object structure to get the next link. Here's a quick example of how you could get the link:
if "next_link" in response["meta"]["pagination"]: next = response["meta"]["pagination"]["next_link"]
In the above code I also show the best way to determine if a next link is present or not, so you know if you need to continue with pagination. You can read more about how pagination works with our API here: https://v2.developer.constantcontact.com/docs/developer-guides/paginated-output.html
Please let me know if you have any questions!
Sincerely,
API Support Engineer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Never mind I must have an error in my original code, it now works. For reference if you use python and requests you get the next link like this:
import requests uri = 'https://api.constanctcontact.com' params = dict ( status = '<status>', limit = '<limit>', api_key = '<apikey>' ) headers = {'Authorization': 'Bearer <your_auth_key>'} current = '<api url>' // Example for contacts it would be '/v2/contacts' r = requests.get(uri + current , params = params , headers = headers ) raw = r.json() // below will print the next link only but you can set as a variable and loop to grab all contacts print raw ['meta'] ['pagination'] ['next_link']
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
It's possible that you might not be going far enough into the object structure to get the next link. Here's a quick example of how you could get the link:
if "next_link" in response["meta"]["pagination"]: next = response["meta"]["pagination"]["next_link"]
In the above code I also show the best way to determine if a next link is present or not, so you know if you need to continue with pagination. You can read more about how pagination works with our API here: https://v2.developer.constantcontact.com/docs/developer-guides/paginated-output.html
Please let me know if you have any questions!
Sincerely,
API Support Engineer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes and thank you!!!!! Will need to add the if statment to my loop, that is great thank you so much!!
