Skip to main content
Archived

Allow to receive JSON format parameter through FMEServer.runDataDownload functio

Related products:Integrations
  • March 4, 2018
  • 3 replies
  • 89 views

takashi
Celebrity

***Note from Migration:***

Original Title was: Allow to receive JSON format parameter through FMEServer.runDataDownload function


I noticed that FME removes every double quotation from a parameter value formatted in JSON if it was passed via the JavaScript API FMEServer.runDataDownload function.

This is a simplified workspace: fme-server-json-parameter.fmw (FME 2017.1.2.1)

If you run it from the FME Server Web UI, the JSON parameter will be preserved correctly. Good.

However, if you run the workspace from an external web application with the API function, FME will removes every double quotation from the JSON parameter, and therefore it cannot be parsed as a valid JSON document. e.g.

<!DOCTYPE html>

<html>

<head><title>test</title></head>

<body onload="onBodyLoad();">

<div id="result"></div>

<script type="text/javascript" src="http://api.fmeserver.com/js/v1.1/FMEServer.js"></script>

<script type="text/javascript">

function onBodyLoad() {

var server = 'https://xxxxxxxxxxxxxxxx.fmecloud.com';

var token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

FMEServer.init({server:server, token:token});

var jsonParams = {

'param1' : "A",

'param2' : "B",

'param3' : "C",

};

var repository = 'Tests';

var workspace = 'fme-server-json-parameter.fmw';

var parameters = 'JOB_PARAMS=' + JSON.stringify(jsonParams);

FMEServer.runDataDownload(repository, workspace, parameters, function (obj) {

var res = obj.serviceResponse;

if (res.statusInfo.status == 'success') {

document.getElementById('result').innerHTML

= '<p><a href="' + res.url + '">download</a></p>';

}

else {

alert('failure.');

}

});

}

</script>

</body></html>

Log:

Is there a way to preserve a JSON parameter correctly in use of the API function?

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

Forum|alt.badge.img

Hi @takashi,

I took a look at your workspace and the parameter you are passing the JSON object to is a Text (Multiline) type parameter. To pass the JSON object correctly to the Data Download service the quotes of the JSON object need to be escaped before they are sent in the post request. Here is an example how you could do this in your script:

var parameters = ('JOB_PARAMS=' + JSON.stringify(jsonParams)).replace(/"/g,'\\\\"');

The JSON Object will be posted like this:

{\\"param1\\":\\"A\\",\\"param2\\":\\"B\\",\\"param3\\":\\"C\\"}

This should give you the result that you expected.

 

When you submit the job via the FME Server Web UI this is already handled by FME Server.

I hope this helps!


takashi
Celebrity
  • Author
  • March 6, 2018
Hi @GerhardAtSafe, I got it. I had to notice escaping is needed here. Thanks for the solution.

 


rylanatsafe
Safer
Forum|alt.badge.img+14
  • Safer
  • March 10, 2022

Please note that we are not planning to upgrade the FME Server JavaScript API—please stay tuned for further official notice on this.

We are making good strides in the development of the V4 REST API, and we welcome any suggestions for improvement that will better support your workflows and applications.

 

There also may be a solution available if you read the previous comments should you run into this issue.