Customer Script: read file keeps returning null

Hi,

I created a simple script that reads out a csv file:

var returned_result = platform.api.get( “files/files/1808.csv” );
print (returned_result);
return returned_result;

When I call this script externally I keep getting the follow reply: (note that script result = null)

"is_user_script":"true",
"app_name":"test",
"path":"system/script/test",
"__tag__":"exposed_event",
"script_result":null

but if I look in the log file, the content of the csv file is logged correctly.

The goal is that i read out the file and do something with the content of the file within the custom script. Why does print work but returning the result not.

Actually, it seems that when i remove the print part, it still writes the full content of the csv file to the log, so i’m doing something wrong where i’m not returning the correct data.

In other words:

var returned_result = platform.api.get( “files/files/1808.csv” ) (same if i use files/files/1808.csv?content=true)

doesn’t return the content, although when using the API Docs, it does return the information in the Response Body

And for what it’s worth: when using a different query: files/files/1808.csv?include_properties=true&content=false it does give me information back:

{
“path”: “files/1808.csv”,
“name”: “1808.csv”,
“content_type”: “text/csv”,
“last_modified”: “Tue, 18 Aug 2015 07:02:33 GMT”,
“content_length”: 10286
}

We have seen the same issue trying to read in a file, but were able to work around it by using an additional library to decode the base64-encoded file contents. After adding this library, I used the following script to return the file contents:

eval(include('base64.js'));

var result = platform.api.get("files/junk/test.txt?include_properties=true&content=true");
var_dump(result);
result = Base64.decode(result.content);
var_dump(result);
return result;

Let me know if this solution works for you also!

Hello Jeffrey, this seems to be working indeed. Thanks for your help.

1 Like

Although it doesn’t work on the new 2.0 platform:

{“error”:{“context”:null,“message”:“Included script “base64.js” not found.”,“code”:500