使用Coldfusion / Railo向Mailchimp API v3.0发送PUT请求时发生401未授权错误

时间:2016-02-09 13:53:47

标签: coldfusion mailchimp railo mailchimp-api-v3.0

我正在为Mailchimp的Restful Services V3.0创建Coldfusion / Railo API包装器。 GET请求工作正常,但我在向Mailchimp提供数据时遇到问题。

我的代码格式为:

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}") ;
  

响应错误   errordetail:401未经授权   filecontent:{“type”:“comment”,“title”:“API Key Missing”,“status”:401,“detail”:“您的请求未包含API密钥。”,“instance” : “”}

我的电话有什么问题?

1 个答案:

答案 0 :(得分:2)

您必须将apikey放在Authorization标头中,请参阅以下示例:

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)