5

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?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Lauren Robinson
  • 443
  • 2
  • 9
  • 26
  • 5
    CF9 does nor understand `:` as used in JSON. Use `=`! ` ` – Bernhard Döbler Mar 29 '18 at 20:44
  • 3
    @BernhardDöbler Enter that as the answer, please. Also note that `logininfo` is not "JSON", in that syntax from CF's point of view, that's an implicit struct. – Adrian J. Moreno Mar 29 '18 at 22:01
  • 5
    I would also not recommend using CF2016 in Dev and CF9 in Production. Make the environments match. If you need to test, Create a Test environment that runs 2016 that you can deploy from Dev. You will lose so much in 2016 if you try to write it for CF9 compatibility. As seen above. – Shawn Mar 29 '18 at 22:16

1 Answers1

10

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

<cfset logininfo = {"username"= "eistech", "password"= "#sat_pw#"}>
Bernhard Döbler
  • 1,960
  • 2
  • 25
  • 39