google-apps-scripturlfetch

Exception: Bad request: https://internal-api.company.com... -Google appscript


I have an internal API that I can check by postman status connected to VPN and with a token that changes daily:

but I have not been able to make the same query from Google Apps Script, I get this error:

Exception: Bad request: https://... .

function nomina() {

  var url = 'https://internal-api.company.com/app-api/master/api/ssff/users';

  var headers= {
  'Authorization' : 'Bearer token',
  'Accept': 'application/json',
  'contentType': 'application/json'

  }

  var options = 
  {
  'method' : 'GET',
  'headers' : headers
  }

  var response = UrlFetchApp.fetch(url,options);
   jsonParse=(JSON.parse(response))  


}

Maybe you could suggest me something to be able to do the API query?

I need to know why it doesn't give me an answer, this is another API that I use and this does bring me information.

I see this similar post but have same error still:

Request to external api to get authentication token in google appscript


Solution

  • Google Apps Script run from the Google servers. It can't use your VPN. You should talk with the responsible of the API and request them to make a connection with Google servers. They might have to involve other people (system and / or networks administrators).