So, I'm trying to get every sent to list from the Mailchimp API. I've made this code to elaborate a list of it to later generate a join and get both the list and the campaign name and not the campaign id only:
try:
client = MailchimpMarketing.Client()
client.set_config({
"api_key": "xxxx",
"server": "xxx"
})
response_id = client.campaigns.list(count=1000)
df_full = pd.json_normalize(response_id['campaigns'])
df_id = df_full['id']
df_id = df_id.values.tolist()
df_id_camp_name = df_full[['id','settings.subject_line']]
#display(df_id)
except ApiClientError as error:
print("Error: {}".format(error.text))
This part of the script gets the ID for each campaign and each campaign name.
for id in df_id:
try:
client = MailchimpMarketing.Client()
client.set_config({
"api_key": "xxxxx",
"server": "xxxx"
})
response_open = client.reports.get_campaign_recipients(id, count=1000)
df_open = pd.json_normalize(response_open['sent_to'])
df_open_full = df_open.append(df_open)
except ApiClientError as error:
print("Error: {}".format(error.text))
df_open_full.to_excel("campaign_reports_mailchimp.xlsx")
And this last piece, takes the ID from the generated list and allegedly runs the code for each ID. Problem is that the generated excel only brings one campaign and doesn't iterates for the rest of the IDs. I know that the API has a limit count but it should move to the next ID once the cap reaches since it restarts the for loop itself.
What could be wrong in this case?
Thanks!