Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
The following command is working:
curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: text/plain' -d 'apiKey=1234' 'https://www.telemetry.com/webservice/token'
But the following code returns empty string.
var request = "https://www.telemetry.com/webservice/token";
var content = new Object();
content.apiKey = '1234';
var headers = new Object();
headers.Accept = "text/plain";
var params = {
headers: headers /* JSON */,
ignoreSSLErrors: true /* BOOLEAN */,
url: request /* STRING */,
content: content /* JSON */,
timeout: 60 /* NUMBER */
};
// result: JSON
var result = Resources["ContentLoaderFunctions"].PostJSON(params);
----------------------------------------------------------------------------------------------------------
How to handle the REST call? how to use x-www-form-urlencoded authentication? How to pass the apiKey?
Hey Mahboob,
You can post a x-www-form-urlencoded request using the PostText service on the ContentLoaderFunction resource. Here is an example:
var params = {
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
url: "" /* Your auth url*/,
content: "" /* Your auth content. This is usually a param list like param1=one¶m2=two. I usually use Postman to create and test the request, then use it to generate a code snippet for http and this will be the last line. */
};
var result = Resources["ContentLoaderFunctions"].PostText(params);
If you're expecting JSON as a result, you can parse it normally using something like:
result = JSON.parse(result);
Hope this helps!