Search code examples
google-apps-scriptweb-applicationsurlfetchquota

Webapp executed by user account: How are quotas applied for UrlFetchApp executions by service account?


Reviewing various SO posts (such as this) regarding quotas, the circumstances are so varied that I'm unclear how they apply to the webapp I'm working with. Here are features of this webapp that may bear on quotas:

  1. Web app is in a "[email protected]" account.
  2. Web app runs under the user, with access by any Gmail user.
  3. Permissions for the webapp project are: userinfo.email; script.external_request; and script.send_mail.
  4. Read/writes to Google spreadsheets are performed by a project service account via UrlFetchApp executions, where the spreadsheets are shared with the service account.
  5. Permissions for the service account are: spreadsheets and script.external_request.

The quotas of concern are those that apply to the webapp project and its service account, not those applied to the individual users.

For example, if limit of 30 simultaneous executions applies to the service account, then this could be a big problem as there certainly can be more than 30 users concurrently launching executions (including UrlFetch performed by the service account). Or do the quotas apply separately to each "instance" of the service account for each user?

So, the basic question: Which quotas are going to apply to the project or to the cumulative actions of its service account on behalf of all users?

MORE SPECIFICALLY

With webapp executed as user and access by any Gmail account, is execution of the following code allocated (under Google Service quota policies) to the user's quotas or to the webapp project/service account quotas?

 var clientToken = //Service account's oAuth authentication token
 var urlSheet = `https://docs.google.com/spreadsheets/d/${ssID}/gviz/tq?tqx=out:json&gid=${sheetId}&tq=${encodeURI(query)}`;

 var res = UrlFetchApp.fetch(urlSheet, {"method": "get", headers: {authorization: "Bearer " + clientToken}}).getContentText();

Thanks for any clarifications about this.


Solution

  • As mentioned here, UrlFetchApp calls will be counted against the service account making the call, as this is the one being used to make them.

    All other services, such as using SpreadsheetApp or any other service offered by Google Apps Script, will be counted against the account of the user running the script: Apps Script quota apply per user invoking a service..