NoryB NoryB - 10 days ago 7
JSON Question

ColdFusion and SmartSheet API

I'm attempting to call the smartsheet.com api and read the JSON data from a list sheet request. Im new to API's so I'm certain I'm missing much with my code.

Here is what I have so far:

<cfscript>
apiURL = "https://api.smartsheet.com/2.0/sheets";
apiToken = "xxxxxxxxxxxxxxxxxxxxxxxxx";
</cfscript>

<cfhttp url="#apiURL#" method="GET" result="httpResp" timeout="120" charset="utf-8">
<cfhttpparam type="header" name="Authorization" value="Bearer #apiToken#" />
</cfhttp>


However I do not receive the desired response:

CFDumpImage

I was attempting to use the sample provided to retrieve the data:

SmartSheet API 2.0
Example Request:

curl https://api.smartsheet.com/2.0/sheets -H "Authorization: Bearer ACCESS_TOKEN"


Example Response:

{
"pageNumber":1,
"pageSize":100,
"totalPages":1,
"totalCount":2,
"data":[
{
"accessLevel":"OWNER",
"id":4583173393803140,
"name":"sheet 1",
"createdAt":"2015-06-05T20:05:29Z",
"modifiedAt":"2015-06-05T20:05:43Z"
},
{
"accessLevel":"OWNER",
"id":2331373580117892,
"name":"sheet 2",
"createdAt":"2015-06-05T20:05:29Z",
"modifiedAt":"2015-06-05T20:05:43Z"
}
]
}

Answer

What version of CF? Looks similar to this issue: ColdFusion 9.0.1 - 3574332 CHTTP returns filecontent as java.io.ByteArrayOutputStream when mimetype is application/json. The workaround is to either:

  • Set the CFHTTP attribute getasbinary="never" OR
  • Convert the returned fileContent object into a string using:

     <cfset rawJSONString = httpResp.fileContent.toString()>