Search code examples
web-servicesgoogle-apps-scriptnetsuitesuitescript

How to call netsuite restlet externally?


I have Tried from google script but getting error:

'USER_ERROR error message:No Authorization header'

var url = 'https://debugger.na1.netsuite.com/app/site/hosting/restlet.nl?script=107&deploy=1';

var header = {
    contentType: 'application/json',
    Authorization: 'NLAuth nlauth_account=TSTDRVXXXXX,    [email protected], nlauth_signature=XXXXXXX, nlauth_role=3',
    method: 'GET',
    muteHttpExceptions: true
  };

  var response = UrlFetchApp.fetch(url, header);

Solution

  • You should review the docs for UrlFetchApp. You've collapsed headers and optional params. The setup should be more like:

    var params = {
        contentType: 'application/json',
        headers:{Authorization: 'NLAuth nlauth_account=TSTDRVXXXXX, [email protected], nlauth_signature=XXXXXXX,     nlauth_role=3'},
        method: 'GET',
        muteHttpExceptions: true
    };
    var response = UrlFetchApp.fetch(url, params);