How to send header info in cfhttpparam

2.1k Views Asked by At

I have been given the following directions to pull a JSON list of data from a webservice.

GET /criminal_api/1.0/service/requests
HTTP Header: Authorization: Bearer 6EDC52118E164AE659EA2C772F3B9804

The following values in the header Bearer 6EDC52118E164AE659EA2C772F3B9804 are dynamic and will be set using the following content variable

 <cfset content = deserializeJSON(    {
       "access_token": "84F224956C6AB5287038C0209EBAC5AB",
       "token_type": "bearer",
       "refresh_token": "E48BB9C164FE2125D3BE2CD602E4A692",
       "expires_in": 7199,
       "scope": "read write"
    })>

So I am tried the following:

<cfhttp method="get" url="https://test.mywebsite.com/criminal_api//1.0/service/requests" result="orderList">
    <cfhttpparam type="HEADER" name="Authorization" value="#content.token_type# #content.access_token#">
</cfhttp>

But when I check the filecontent instead of getting a JSON list I get: Connection Failure

I have a feeling it is how I am setting the header value I am just not sure what I am doing wrong.

EDIT: When I added a ":" in between the token type and access token I got a new error:

struct
error   -1
error_description   Invalid access token: : 82D773278FB69CFBCFB4CB8CEF8AC03D

Obviously it thinks the ":" is part of the access token so it is connecting I am just not sure how to have both values in the value= field so it is read correctly.

1

There are 1 best solutions below

0
On

Have you tried:

<cfhttp method="get" url="https://test.mywebsite.com/criminal_api//1.0/service/requests" result="orderList" username="#content.token_type#" password="#content.access_token#">

This will produce an authorization header of "Basic Bearer:6EDC52118E164AE659EA2C772F3B9804"

Manually, that would be:

<cfhttp method="get" url="https://test.mywebsite.com/criminal_api//1.0/service/requests" result="orderList">
<cfhttpparam type="HEADER" name="Authorization" value="Basic #content.token_type#:#content.access_token#">

There's also the question of what that hex value contains. Take a look at Getting Basic Authentication to work with ColdFusion - maybe this more closely reflects your situation.