VPC Static IP for Sheets Add-On for UrlFetchApp.fetch - google-apps-script

I have a Google Apps Script Project that is an "add-on" for Google Sheet.
It does a "get" through UrlFetchApp to retrieve some info through an API.
The company with the API requires a static IP (Mercury Bank), which has to be whitelisted on the Mercury website through 'settings'.
In GCP I created a Virtual Private Cloud with a subnet and a static IP.
When I run the code I get "Exception: Request failed for https://api.mercury.com returned code 401. Truncated server response: {"errors":{"message":"That token may not be used from the current IP Address, which is: 107.178.203.205"}} "
When I run it again I get the same error, but with a different IP.
How do I tell Google Cloud to run the apps script using the static IP?
THANKS!

Related

Azure API Management IP for whitelisting

I have a bunch of app services listed in API management. These services call third party clients who want to whitelist my IP
I would like to give them the public IP address of the APIM instance. I tried to check this by having my app service hosted in APIM call a dummy function app I had created. In the dummy function app I logged the header details.
It appeared that the IP coming through was that of the app service and not the APIM instance. I was expecting (and hoping) it to be the APIM IP
See on APIM overview page, public IP will be visible in the top section
APIM is only a gateway in front of app service. It is not a host environment for app service. So if you call 3rd party services from within the app service, the IP of the caller will always be the app service. It won't be the IP of APIM. Actually the call won't go through APIM at all.

Getting 401 Unauthorized error on google API

I am learning how to use Google Drive API to upload a file and I am getting this error:
"Client error: `POST https://www.googleapis.com/oauth2/v4/token` resulted in a `401 Unauthorized` response:\n{\n \"error\": \"unauthorized_client\",\n \"error_description\": \"Client is unauthorized to retrieve access tokens using this me (truncated...)\n"
I think this stem from a wrong configuration of my service account. When I created my service account, I didn't use Enable G Suite Domain-wide Delegation and just used the generated json key.
Attached here is a screenshot of my IAM & ADMIN
I also enabled API for google drive, so what am I missing?
You have to create a client id for the service account and with that id you have to enable the SCOPE in security - advanced configuration

Google Cloud SQL Add Authorized Network

Trying to connect to my Google Cloud SQL Instance. I'm at the part where I have to add an authorized subnet. I keep trying to add a new subnet but whenever I do the page tells me it couldn't complete the operation. I'm putting my IP address in CIDR format like "192.168.103.202/24", but it just won't get accepted. And I can't connect to the SQL instance without this piece. Help? Is it a bug or am I doing something wrong???
if I try to connect to my google cloud sql instance without the subnet added I get the error:
I keep getting the error 'If Google Cloud SQL rejects the connection, for example, because the IP address your client is connecting from is not authorized, the error you receive will be'
which is expected as per the docs
reference:
https://developers.google.com/cloud-sql/docs/access_control
192.168.103.202 is your internal IP address, which is not publicly accessible, you need to enter your public IP address into the authorized network dialog.
The easiest way to get this is to enter "whats my ip" into Google and it will tell you "Your public IP address is x.x.x.x".

How to access Google Cloud SQL from domain's user account via google Apps Script

Admin of a domain created a Google Cloud SQL instance....Now a user of that domain wants to access Google Cloud SQL via google Apps Script, but he is not able to access....
When I run this code from admin account it works :
var conn = Jdbc.getCloudSqlConnection("jdbc:google:rdbms://"+instance_name+"/"+database_name,"root","");
but when i run this code from a domain user then it gives this error :
Failed to establish a database connection. Check connection string, username and password.
Does that user have access to the database ? see doc here. Or you can also provide userName and password as advanced arguments in parameters

API URL for internal google earth enterprise

My company has an internal google earth enterprise server. I can get to it via http://local/default_map
I like to switch from the public API server, <script src="http://maps.google.com/maps/api/js?v=3&sensor=false"></script>, to the internal one.
But http://local/maps/api/js?v=3&sensor=false returns Forbidden error: You don't have permission to access /maps/api/js/ on this server.
How can I find out if the internal server supports the API feature and how to configure it?