Can Apps Script list forwarding addresses for individual users without listing each in the urlFetchWhitelist

94 views
Skip to first unread message

Dustin Christlieb

unread,
Jul 1, 2024, 4:31:17 PM7/1/24
to Google Apps Script Community

I am trying to list forwarding addresses configured by users in Google Workspace. The code seems to work, but I'm receiving errors about the request failing because the URL has not been whitelisted in the script manifest. I am a Super Admin, using a service account, I have enabled the Gmail API on my project and in the Apps Script service. I have set up domain wide delegation, but I cannot list the unique URL for each user in the script manifest and using urlFetchWhitelist addresses (because once the app is completed, admins would run this on their own environment and the userlist is unknown until the script is run.)

"https://gmail.googleapis.com/gmail/v1/users/*", "https://gmail.googleapis.com/gmail/v1/users/*/settings/forwardingAddresses", "https://gmail.googleapis.com/gmail/v1/users/test...@example.com/settings/forwardingAddresses",

Each user with the exception of test...@example.com listed in the urlFetchWhitelist example above gets an error: Error fetching settings for test...@example.com: Exception: Request to https://gmail.googleapis.com/gmail/v1/users/test...@example.com/settings/forwardingAddresses failed because the URL has not been whitelisted in the script manifest. (Response: Empty)

I have tried listing individual user addresses in the URLwhitelist in the script manifest which does not return an error. I'm expecting to be able to make the API calls to list if a user has forwarding enabled and if so, list the forwarding addresses for each user who has configured it in Gmail settings.

Ed Robinson

unread,
Jul 2, 2024, 8:58:23 AM7/2/24
to Google Apps Script Community
Hi Dustin,
Try using just the prefix of the URL (third level domain) in the whitelist. The whitelist should auto-magically allow anything using this prefix (you don't need to add a wildcard).
Hopefully this will work for the different users.

For example:

"urlFetchWhitelist": [
],

Reply all
Reply to author
Forward
0 new messages