0

I need to connect mailchimp API through python script and GET data, that i'd later move to PowerBI for BI solutions.

I have read the documentation : https://mailchimp.com/developer/guides/get-started-with-mailchimp-api-3/#Parameters

And I am trying to get a specific report https://mailchimp.com/developer/reference/reports/#get_/reports/-campaign_id-

First I managed to connect to reports (https://mailchimp.com/developer/reference/reports/#get_/reports/) with the following code:

import requests
import json

r=requests.get("https://us11.api.mailchimp.com/3.0/reports/", 
               headers={"content-type": "application/json"}, 
               auth=('anystring', 'myapikey')
               ,params={'fields':['id']})

data=r.json()
print(data)
r_dict = json.loads(r.text)
print(r.status_code)
print(r.text)

for i in r_dict:
   print("key:", i,"val",r_dict[i])

Then I get some sort of output, which is not an error and it seems i connected since i retrieved data. Now I am trying to connect to a specific report, i set up an id, but it seems i cannot understand how to set up parameters properly. My code looks like this:

r=requests.get("https://us11.api.mailchimp.com/3.0/reports/{80419197aa}", 
               headers={"content-type": "application/json"}, 
               auth=('anystring', 'myapikey')
               ,params={'fields':['id','campaign_title','type','list_id']})

data=r.json()
print(data)
r_dict = json.loads(r.text)
print(r.status_code)
print(r.text)

for i in r_dict:
    print("key:", i,"val",r_dict[i])

Then i get this error:

{'type': 'http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/', 'title': 'Resource Not Found', 'status': 404, 'detail': 'The requested resource could not be found.', 'instance': '13af7a5e-9868-4dd3-abd6-6c3b0b58983f'} 404 {"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"Resource Not Found","status":404,"detail":"The requested resource could not be found.","instance":"13af7a5e-9868-4dd3-abd6-6c3b0b58983f"} key: type val http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ key: title val Resource Not Found key: status val 404 key: detail val The requested resource could not be found. key: instance val 13af7a5e-9868-4dd3-abd6-6c3b0b58983f"

Could anyone help me how should i specify the parameters, because i suppose the mistake is there?

1 Answer 1

0

The reason why error 404 appears is because of the auth parameter, if you remove this parameter you will get the error 401 that is an invalid API Key, you would need to use the correct authentication method.

I would recommend that you first try it with a program like Postman, so that you discard some error outside the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.