Article - CS337595

How to call external Rest API which accepts headers and body as input in ThingWorx

Modified: 06-Aug-2021   


Applies To

  • ThingWorx Platform 8.5 SP5

Description

  • How to call external Rest API which accepts headers and body as input
  • Accessing a share point giving error via rest API in ThingWorx
  • Below code is working with postman but giving error in ThingWorx
  • var url = 'url of share point'
    var header = {};
    header['Content-type'] = 'application/x-www-from-urlencoded';type
    ']='application/x-www-form-urlencoded';
    var body= {};
    body['grant type'] = ]client credentials';

    body['client_id']='<your client id>';
    body['client_secret']='<your client secret>'; body['resource'] = '<your resource>';

    var params = {
    headers: header /* JSON */,
    url: url /* STRING */,
    content: body /* JSON */,
    };

    // result: JSON
    var result = Resources["ContentLoaderFunctions"].PostJSON(params);

​​​​​

This is a PDF version of Article CS337595 and may be out of date. For the latest version click https://www.ptc.com/en/support/article/CS337595