Home > Net >  Google App Script throw BAD request , Postman and Curl OK, even browser callback
Google App Script throw BAD request , Postman and Curl OK, even browser callback

Time:03-23

I am trying to run the below code over the Google App Script for Gitlab which is in VPN.

The VPN is connected and I can get responses on Curl Command, Browser, and Postman but the Google App script is giving an error.

this._url = "https://<url access on vpn and vpn is on>/api/v4/projects/1048/repository/compare?to=release/1.209.0&from=release/1.208.0"; this.payloadData = null;

this.fetchArgs = {   contentType: "application/json",   headers: { "Authorization": "Bearer <mytoken-accesible on Postmand and Curl>" },  muteHttpExceptions: true,   method: methodType, }

try {   this.responseData = UrlFetchApp.fetch(this._url, this.fetchArgs);   this.responseCode = this.responseData.getResponseCode(); } catch (e) {   console.log(e); }

Response is always as below

{ [Exception: Bad request: https://<baseURL>/api/v4/projects/1048/repository/compare?to=release/1.209.0&from=release/1.208.0] name: 'Exception' }

CodePudding user response:

If you need VPN to access the link, and you were able to access it using Postman, curl and browser but apps script doesn't, that is because all those 3 accesses the URL locally thus they can access it with VPN.

In the other hand, Apps Script does that remotely (they run on google servers), therefore, you are accessing the URL without any VPN, causing the bad request issue.

It is said that you could use SDC for these issues but it is already deprecated.

Reference:

CodePudding user response:

This answers my question after investigation, seems Google has stopped supporting API behind firewall so have to build something inside. Wish google can think over this.

Does code on a Google sheet runs locally or on a Google server? - UrlFetchApp returns empty

  • Related