SurveyMonkey api Coldfusion issue

I'm having trouble getting the header param "Authorization" to work correctly using cfhttp and cfhttpparam.

The connection is working fine... I am getting out through our proxy so that's not the issue.

The api documentation states that "Authorization" in the header should be formatted as "Authorization:bearer XXXYYYZZ".

When I try to add the "bearer" with a space after it I get the following error: {"status":3,"errmsg":"Expected object or value"}

When I do not add the prefix "bearer" at all I get the following error: {"status":1,"errmsg":"Invalid "Authorization" data in request header"}

I've tried "bearer XXXYYYZZ" and "bearer%20XXXYYYZZ" and "bearer XXXYYYZZ" as well with the same results.

Any ideas? Thanks!

CODE:

<cfhttp 
    timeout="2000" 
    url="https://api.surveymonkey.net/v2/surveys/get_survey_list/?api_key=xxxx"
    proxyserver="proxy.xxxx.com" 
    proxyport="8080" 
    method="post" 
    result="httpResponse" 
    charset="utf-8"
    throwonerror="Yes">
    <cfhttpparam type="header" name="Authorization" value="bearer XXXYYYZZ">
</cfhttp>
<cfdump var="#httpResponse#">

RESPONSE:

Charset UTF-8
ErrorDetail [empty string]
Filecontent {"status":1,"errmsg":"Invalid "Authorization" data in request header"}
Header HTTP/1.1 200 OK Access-Control-Expose-Headers: Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,Date,Content-Length Content-Type: application/json; charset=UTF-8 Date: Thu, 28 Jan 2016 13:16:11 GMT Server: nginx/1.4.6 (Ubuntu) SM-Request-ID: 251952a7-9d21-470e-807d-9b48adf0892b X-Mashery-Message-ID: 9ebad058-e4e5-4cc9-b9cf-bf33dee9fbc6 X-Mashery-Responder: prod-j-worker-us-west-1b-58.mashery.com X-Plan-QPS-Allotted: 6 X-Plan-QPS-Current: 1 X-Plan-Quota-Allotted: 7000 X-Plan-Quota-Current: 5 X-Plan-Quota-Reset: Friday, January 29, 2016 12:00:00 AM GMT Content-Length: 72 Connection: Close
Mimetype application/json
Responseheader

struct

Access-Control-Expose-Headers Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,Date,Content-Length
Connection Close
Content-Length 72
Content-Type application/json; charset=UTF-8
Date Thu, 28 Jan 2016 13:16:11 GMT
Explanation OK
Http_Version HTTP/1.1
SM-Request-ID 251952a7-9d21-470e-807d-9b48adf0892b
Server nginx/1.4.6 (Ubuntu)
Status_Code 200
X-Mashery-Message-ID 9ebad058-e4e5-4cc9-b9cf-bf33dee9fbc6
X-Mashery-Responder prod-j-worker-us-west-1b-58.mashery.com
X-Plan-QPS-Allotted 6
X-Plan-QPS-Current 1
X-Plan-Quota-Allotted 7000
X-Plan-Quota-Current 5
X-Plan-Quota-Reset Friday, January 29, 2016 12:00:00 AM GMT

Statuscode 200 OK
Text YES


Looks like you need to send an empty JSON struct in the body. The API requires a JSON input, even if there are no parameters to be sent in. Just add another cfhttpparam of type body with a value of {}

<cfhttp 
    timeout="2000" 
    url="https://api.surveymonkey.net/v2/surveys/get_survey_list/?api_key=xxxx"
    proxyserver="proxy.xxxx.com" 
    proxyport="8080" 
    method="post" 
    result="httpResponse" 
    charset="utf-8"
    throwonerror="Yes">
    <cfhttpparam type="header" name="Authorization" value="bearer XXXYYYZZ">
    <cfhttpparam name="body" type="body" value="{}">
</cfhttp>
<cfdump var="#httpResponse#">

<cfhttp 
    timeout="2000" 
    url="https://api.surveymonkey.net/v2/surveys/get_survey_list/?api_key=xxxx"
    proxyserver="proxy.xxxx.com" 
    proxyport="8080" 
    method="post" 
    result="httpResponse" 
    charset="utf-8"
    throwonerror="Yes">
    <cfhttpparam type="header" name="Authorization" value="bearer XXXYYYZZ">
    <cfhttpparam type="header" name="Content-Type" value="application/json" />
    <cfhttpparam name="body" type="body" value="{}">
</cfhttp>
<cfdump var="#httpResponse#">
链接地址: http://www.djcxy.com/p/31228.html

上一篇: CFHTTP和IIS 7连接故障(不SSL)

下一篇: SurveyMonkey api Coldfusion问题