Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CF accepts JSON string in cf2016 but not in cf9

I am calling an API and need to send it a JSON string with credentials. We are currently transitioning from CF9 to CF2016. In DEVL I have both versions. In Test and Prod I currently have CF9 only. Originally I wrote the code and tested on CF2016 and it worked fine. When I pushed it up to Test, it did not work. I retried in DEVL, on CF9, and it also errors. The code is:

<cfset logininfo = {"username": "eistech", "password": "#sat_pw#"}> 
<cfset fromdate=dateformat(DateAdd('d', -1, dat), "yyyy-MM-dd") & 'T00:00:00-0500'>

<!--- Get token info--->
<cfhttp url="https://scoresdownload.collegeboard.org/pascoredwnld/files/list?fromDate=#fromdate#" method="post"  result="finfo">
    <cfhttpparam name="Content-Type" type="HEADER" value="application/json">
    <cfhttpparam name="Accept" type="HEADER" value="application/json">
     <cfhttpparam type="body" value="#serializeJSON(logininfo)#">
</cfhttp>

When running it in CF9, I get:

Invalid CFML construct found on line 5 at column 20. ColdFusion was looking at the following text: { (Line 20 is <cfset logininfo = {"username": "eistech", "password": "#sat_pw#"}>

I tried enclosing it in single quotes, but this fails in both instances. How can I get this to work in both CF2016 and CF9?

like image 506
Lauren Robinson Avatar asked Mar 29 '18 20:03

Lauren Robinson


1 Answers

CF9 does not understand : as used in the JSON string in the question. Use =!

<cfset logininfo = {"username"= "eistech", "password"= "#sat_pw#"}>
like image 155
Bernhard Döbler Avatar answered Sep 30 '22 06:09

Bernhard Döbler