Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
Hello guys,
I have a service in ThingWorx 9 where I am trying to use the GetJSON from ContentLoaderFunctions to get the data for a ThingWorx project but I get the following error: " Message :: Invalid Content Type: text/html". I checked the logs and there are no other errors.
I tried to do this request from Postman and it works fine. Also tried a PostJSON and it works fine, so the appKey it's ok. I also tested the javascript from below with ThingWorx 8.5 and it works without any issues...but for ThongWorx 9 it simply does not work.
You can find below the javascript code from my service:
var params = {
headers: {
"appKey": "6b2c8c8b-423e-5a56-c321-5e378ff55662",
"Content-type": "application/json"
} /* JSON */,
url: "http://localhost/Thingworx/Projects/daniel_test_99" /* STRING */
};
var result = Resources["ContentLoaderFunctions"].GetJSON(params);
If it's important "daniel_test_99" it's a local Project with no dependencies.
ThingWorx version: 9.0
Do you have any idea why it's not working?
Thanks!
I have the same problem!
What's the output type of GetJson service and your own script?
Output type is JSON.
The workaround I used is to use GetText() instead, but then you need to parse the result to json.
Since you've tested through Postman and TWX 8.5, then this script should be okay;
You're not getting 401 error, so the server's external connection is correct;
I asked what's the output type of your script to check if you forget to change the output from Nothing to Json, because it sometimes happen to me;
After all these, there might be some difference or even bug in the TWX 9 , you may create a case for it and let TS contact R&D.
Hi,
Add the Accept header in your request,
var params = {
headers: {
...
"Accept": "application/json"
} /* JSON */,
};
This will tell the server to respond with a JSON.
In the response headers, content-type tells you what the server actually sent back.
if you added the Accept header asking for a JSON but got text/html, notify the owner of the server that if the server cannot respond in accordance to the Accept cookie it should return a 406.
most likely it will be fixed and the server will return a JSON.
Thanks,
Arkady.
Hope this works.
Hi @DV_9683959.
If one of the previous responses allowed you to find a solution, please mark the appropriate one as the Accepted solution for the benefit of others with the same issue.
Regards.
--Sharon