4

I'm creating a Coldfusion/Railo API Wrapper for Mailchimp's restful Services V3.0. GET requests are working fine but I'm having problems PUTTING data to Mailchimp.

My code format is:

httpService.setMethod("PUT") ;

httpService.setURL("https://us12.api.mailchimp.com/3.0/lists/d9****81/members/e311cfde*****************2dda77c0") ;

httpService.addParam(type="URL",name="apikey", value="*******************-us12"); 

httpService.addParam(type="URL",name="user", value="jnicola2:******************-us12"); 

httpService.addParam(type="BODY",name="status", value="Subscribed") ;

httpService.addParam(type="BODY",name="email_address", value="*****@*****.co.uk") ; 

httpService.addParam(type="BODY",name="interests", value="{"ae4****7e5":true,"675****75a":true,"1ab****7f":false,"cf0****8ef":true,"38be****2a":false}") ;

RESPONSE ERROR errordetail: 401 Unauthorized filecontent: {"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"API Key Missing","status":401,"detail":"Your request did not include an API key.","instance":""}

What's wrong with my call?

ekad
  • 14,436
  • 26
  • 44
  • 46
Cuppa T Lager
  • 41
  • 1
  • 3

1 Answers1

3

You have to put the apikey in the Authorization header, see this example:

var requestBody = {"email_address"="*****@*****.co.uk", "status"="subscribed"};

httpService = new 
http(url="https://us12.api.mailchimp.com/3.0/lists/d9****81/members",method="POST",timeout=3);

httpService.addParam(type="header", name="Content-Type", value="application/json");

httpService.addParam(type="header",name="Authorization", value="apikey *******************-us12");

response = httpService.send().getPrefix();

dump(response)
Tom Sucaet
  • 31
  • 4