API Rest get JSON


has anyone experience with api rest json in Lucee/CF ?
I would like to call this link but as i need a token + auth_mode, what is the best solution to call this, any advice, link, suggestions?

Thank you so much for your support





body of json reques see belowt


grant_type: password,

client_id: xxxxxx-xxxxxx-xxxxxx-xxxxx-xxxxxxx,

username: test,

password: test1111


Hi Stephen,

I’d to it like this:

<cfset auth_mode = "abc" />
<cfset api_key = "xyz" />

<cfset bodyData = structNew() />
<cfset bodyData['grant_type'] = "password" />
<cfset bodyData['client_id'] = "xxxxxx-xxxxxx-xxxxxx-xxxxx-xxxxxxx" />
<cfset bodyData['username'] = "test" />
<cfset bodyData['password'] = "test1111" />        

<cfhttp url="https://xxxxxx/token?auth_mode=#auth_mode#&api_key=#api_key#" result="result">
    <cfhttpparam type="header" name="Content-Type" value="application/json" />
    <cfhttpparam type="body" value="#serializeJSON( bodyData )#" />

<cfdump var="#result#" />

1 Like

hi @lutz thx. for the hint! by trying that i got the following error: “type body is only supported for type post and put”

actually i need to have the “GET” in order to read those information.

Thx Stephen

HTTP GET with body is not usual thing to do and it’s not a good practice since most web servers does not handle body in GET requests because this is only supposed to “send” things and not “receive” things. See this thread:

Hi Stephen,

good catch! The code I used as basis for my sample is actually sending a PUT request.

As @omarpta pointed out, GET requests with a body part are quite unusual, mainly due to changes in the relevant RFCs.

That being said, I sadly have no solution for this, but I happen to know that other languages / libraries have the same restriction. I’d suggest to ask the party offering the API you want to connect to if they have a workaround in place. Seems unlikely that you’re the first to run into this.

There’s also a JIRA ticket asking to change the way Lucee is handling this:

– Lutz

if that’s still happening with the latest release / snapshot, please file a new bug and link it back to that one, as that one is already closed