Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
I am using TWX 9.3.1 , trying to get JSON output thru a JS service using GetJSON/LoadJSON snippet.
I checked it thru POSTMAN and it worked perfectly. This is my code:
var AuthVal = "Bearer "+token;
var ServiceHeader = {"Content-Type" : "application/text",
"Accept" :"application/text",
"Authorization" : AuthVal,
"maxItems":7000};
var url="http://apps-dev.xylem.net/ApisManager/api/MES/Get/BrazedBOM?partNumber=BY568504016017";
let params = {
headers: ServiceHeader /* JSON */,
url: url /* STRING */,
timeout: 0 /* NUMBER {"defaultValue":60} */
};
// result: JSON
var result = Resources["ContentLoaderFunctions"].LoadJSON(params);
and this string output:
{"headers":{"Authorization":"Bearer e6c336482a7d4767883c2268bd1836fe","maxItems":7000,"Accept":"application/text","Content-Type":"application/text"},"responseHeaders":{"X-UA-Compatible":"IE=Edge","Server":"Microsoft-IIS/8.5","Access-Control-Allow-Origin":"*","Content-Length":"6209","Date":"Thu, 25 Aug 2022 06:30:00 GMT","Content-Type":"application/json; charset=utf-8"},"responseStatus":{"reasonPhrase":"OK","protocolVersion":{"protocol":"HTTP","major":1,"minor":1},"statusCode":200}}
HI @KP_9595031,
Did you try retrieving the data using a tool like postman? I would try using this as a first pass external to ThingWorx to validate you are providing all the correct information the target URL is expecting.
Second I noticed that the Accept is "Application/Text", did you try "Application/JSON"?
Thanks,
Travis
I have already confirmed it with POSTMAN, it gives me perfect response.Only when I am using it with GetTEXT ( with content-type:application/text) , it gives"invalid content type".In older version TWX 8.5.9 this service with GetText was working perfectly.Now I am using TWX 9.3.1.I tried GetJSON(with content-type:application/json), it gives here only header and no body.
Hi @KP_9595031.
Can you send your full code (excluding sensitive information) so we can test it here?
Regards.
--Sharon