Skip to main content
1-Visitor
October 31, 2020
Question

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

  • October 31, 2020
  • 4 replies
  • 6517 views

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!

4 replies

5-Regular Member
November 1, 2020

I have the same problem!

5-Regular Member
November 2, 2020

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

1-Visitor
November 2, 2020

Output type is JSON.

5-Regular Member
November 2, 2020

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

5-Regular Member
November 9, 2020

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. 

 

 

1-Visitor
November 10, 2020

Hope this works.

Community Manager
November 11, 2020

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