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?
CF9 does not understand :
as used in the JSON string in the question.
Use =
!
<cfset logininfo = {"username"= "eistech", "password"= "#sat_pw#"}>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With