cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Facing invalid text/html error while using getjson

MM_9023322
14-Alexandrite

Facing invalid text/html error while using getjson

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!

ACCEPTED SOLUTION

Accepted Solutions
MM_9023322
14-Alexandrite
(To:PaiChung)

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 !!

View solution in original post

7 REPLIES 7
PaiChung
22-Sapphire I
(To:MM_9023322)

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

 

MM_9023322
14-Alexandrite
(To:PaiChung)

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?

 

 

PaiChung
22-Sapphire I
(To:MM_9023322)

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

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

MM_9023322
14-Alexandrite
(To:PaiChung)

@PaiChung, I am using GetJson, there is no content or body in getjson.

MM_9023322
14-Alexandrite
(To:MM_9023322)

Hi @PaiChung, I am using the PostMultipart function, and in the "partsToSend" I have updated the client id, secret id in infotable, and in the content type I am using "multipart/form-data; charset=UTF-8", but I am getting Invalid-Request for this!! 

Can you please help me with this!!

PaiChung
22-Sapphire I
(To:MM_9023322)

I've never used this service, so I am unsure what might need to be changed.

MM_9023322
14-Alexandrite
(To:PaiChung)

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 !!

Announcements


Top Tags