Search code examples
google-sheetsgoogle-sheets-api

Test service account can write a google sheets spreadsheet


I am wondering if there is an api I can use to test if a service account has write access to a google spreadsheet, I know you can do that with other APIs using the testIamPermissions permission, but there does not seem to be an equivalent for sheets api.

Currently I am actually testing write access by trying to write a developer metadata property, which is not ideal because it generates a version of the spreadsheet :-(


Solution

  • Google Sheet Permission List:

    I understand that you are looking to check if a service account has access to your spreadsheet without using a write method that generates a version.

    Due to the nature of the service account needed to be added on permission's list you can use Google Drive Permissions API. Here on this link. Using that should generate a list of permitted accounts and with a little play around the fields you can get the exact emails.

    Screenshot Reference of the Permission's API:

    On the screenshot you can see my service account listed and other email for testing purposes.

    Screenshot of the JSON Response:

    enter image description here

    Screenshot of Current Permissions:

    enter image description here

    Screenshot revealing the file emailAddress fields:

    enter image description here

    ==================================

    References:

    Google Drive API Permissions