0

When running the code from AppsScript Editor with an associated GCP.

Is there a way to fetch the API key for the desired API with any environment variable?

How to infer an API Key to a UrlFetchApp in Google Apps Scripts?

     function myFunction() {
          var apiKey = 'Your API Key'; 
          var url = 'https://api.forecast.io/forecast/' + apiKey +"/" + lat +"," + long;

  var response = UrlFetchApp.fetch(url); // get api endpoint

I don't want to put it manually, let alone in the code

1 Answer 1

1

You can use Properties service to fetch the API key. You can store all keys in Properties service and use it in the script.

According to the documentation, the Properties service lets you store simple data in key-value pairs scoped to one script, one user of a script, or one document in which an add-on is used. It is typically used to store developer configuration or user preferences. Properties are never shared between scripts.

See reference link for your guide: https://developers.google.com/apps-script/guides/properties

1
  • Thanks, is there a way to infer an API Key from the GCP which is associated to the current Google Apps Script? Feb 17, 2021 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.