Reputation: 481
I am trying to get mailchimp campaign ID using /campaigns/list
endpoint.
Then I need to use the id to invoke /reports/unsubscribes
endpoint. Here is my code using mailchimp python sdk:
m = get_mailchimp_api()
campaigns = m.campaigns.list()
for campaign in campaigns['data']:
cid = campaign['id']
title = campaign['title']
unsubscribes = m.reports.unsubscribes({'cid':cid})
This code is throwing mailchimp.CampaignDoesNotExistError: Invalid Campaign ID: Array
exception.
If id
field does not have campaign id then which field would have? I have tried all other fields that had id
in them but without luck.
Upvotes: 1
Views: 2448
Reputation: 87124
campaign['id']
is the correct id to use, but you need to pass the id directly, not in a dictionary, i.e.:
unsubscribes = m.reports.unsubscribes(cid)
Upvotes: 2