Skip to main content
15-Moonstone
June 16, 2022
Solved

Facing invalid text/html error while using getjson

  • June 16, 2022
  • 1 reply
  • 2915 views

Hi all,

I am trying to generate a bearer token from azure on Thingworx (9.3.2) using getJSON function,  but I am facing "Message :: Invalid Content-Type: text/html - See Script Error Log for more details" this issue. When I tried it from the postman, it was working fine! I am using the below URL and headers in my code

 

var url = "https://login.microsoftonline.com/XXXXXXXXXXXxX/oauth2/token";

var headers = {
"Accept": "text/html",
"Content-Type": "text/html",
"grant_type": "client_credentials",
"client_id": "XXXXXXXXXXXXXXXXXXXXXXXXXX",
"client_secret" : "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"resource" : "https://servicebus.azure.net"
};

 

Thank you!

Best answer by MM_9023322

I have found the solution for my issue, I am able to generate the bearer token in thingworx using the PostText method, I gave the content in a string and content type as "application/x-www-form-urlencoded".

 

Thank you for your help @PaiChung !!

1 reply

22-Sapphire I
June 17, 2022

Thingworx won't do text/html try text/xml instead

 

15-Moonstone
June 20, 2022

Hi @PaiChung,

 Thank you for the response. While creating the token from the postman, I wrote the "grant_type": "client_credentials",
"client_id": "XXXXXXXXXXXXXXXXXXXXXXXXXX", "client_secret" : "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "resource" : "https://servicebus.azure.net" under form-data -> body of postman. How to write this body part in Thingworx?

 

 

22-Sapphire I
June 21, 2022

Within the contentloader functions I believe the 'body' is called 'content'

So you would have to create that content similar to the body.