Hello again everyone,
I have a question for anybody who's worked with passing JSON data in the body of a POST request for a webhook.
I am working with a developer on a script to call FME server from an outside application and pass the needed JSON data in the body. She is using an AJAX script that looks somewhat like this:
$.ajax({
url: <my server url with webhook token>,
method: 'POST',
data: {"A":"1",
"B":"2",
"C":"3",
},
dataType: "json",
success: function (response) {
alert(JSON.stringify(response));
},
error: function(data, errorThrown){
alert('request failed :'+errorThrown);
//document.getElementById("response").innerHTML="Failed"+errorThrown;
}
});
Here's the thing: I have a separate HTTPCaller on a 'tokentester' workbench (as a substitute for something like POSTMAN) and it works fine through there. In this case, I have all the headers and the JSON is being passed through the 'Specify Upload Body' option.
When I look through the logs of my requests (ie. done through HTTPCaller) I see that the URL submitted to the server under 'FME_SERVER_REQUEST_URI' is <my server url with webhook token> (so, exactly what I would expect). The server is able to use the JSON as passed through HTTPCaller and the request is a success.
However, when I see the logs from her requests, the 'FME_SERVER_REQUEST_URI' value is something like: "<my server url with webhook token>&A=1&B=2&C=3". In other words, FME Server is receiving her AJAX request as the URL PLUS the JSON's individual elements in the same string. The server then throws an error saying it can't find the original JSON file uploaded with the workbench.
In other words, FME Server is receiving the request with all the data embedded in the URL in a way it doesn't understand (or expect) and so thinks the JSON body is missing, thus it defaults to the 'original' file uploaded with the workbench.
I'm not very familiar with AJAX and its methods to send requests. Does anyone have an idea as to what might be going on? Is there something that can be added to the code so FME Server gets the right request, or perhaps something I need to tweak on my own end in the workbench?
Thanks for reading! Any insight is most welcome!