Skip to main content
1-Visitor
Oct 31, 2020 2:42 PM UTC
Question

Error executing GetJSON in service - Invalid Content Type: text/html

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!

8 replies

5-Regular Member
Nov 1, 2020 4:34 PM UTC

I have the same problem!

Translate
5-Regular Member
Nov 2, 2020 6:49 AM UTC

What's the output type of GetJson service and your own script?

Translate
1-Visitor
Nov 2, 2020 7:56 AM UTC

Output type is JSON.

Translate
5-Regular Member
Nov 2, 2020 2:26 PM UTC

The workaround I used is to use GetText() instead, but then you need to parse the result to json.

Translate
5-Regular Member
Nov 9, 2020 4:28 PM UTC

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. 

 

 

Translate
1-Visitor
Nov 10, 2020 3:47 AM UTC

Hope this works.

Translate
Support
Nov 11, 2020 1:49 PM UTC

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

Translate