GSuite Activity Gmail API Service Account Authentication

Hi @Mihai_Dunareanu,

The issue is with IT giving access to domain wide authentication. The scope has been configured correctly otherwise, I am now just waiting on my IT team to give the proper access.

Thank you!


I would like to know further information on this matter.
I face the same problem.
After writing a topic like the link below in the UiPath Forum, I found your topic.

Please tell me what Roles you gave your service account in the GCP IAM settings.


I did not understand you have Service Account Key or you want to use OAuth…

If you are using Service Account key, you need to have service account on gsuite. and then download json file and copy it to shared location.

then in drop down many choose Service key, fill only this 2 lines and it will work.


Hi @Mihai_Dunareanu
I am using Get mail message activity inside Gsuite with “ServiceAccountkey” as authentication type. while executing i found an error as "Precondition not met[404].
My question is Will bot checks for mail to read in the service account created? or any user mail has to be defined?
Please help at the earliest.
please find the image. These are the properties i have filled

Hi all,

Please help me with the above mentioned query. I am at urgency.
When we use authentication type as “Service account” , is it possible to search for the required mail at “any Gmail user account” or only for the account where the service account has been created? Kindly advise

Service account key

A service account key is a special type of Google account that belongs to your application instead of to an individual end-user. Your application calls Google APIs on behalf of the service account, so users aren’t directly involved. For more information about Service account keys, see Understanding service accounts in the Google Cloud Documentation.

@marian.platonov Hi Marian, thank you very much for the reply.
My scenario is like I want to read a mail with attachment from Gmail account using service account key authentication. I am using Get mail message activity inside Gsuite scope. Please help to do the same?
How can we indicate in which gmail user account the mail has to be searched for?
Kindly advise


Assuming that you configured correctly the Service Account in your Google Cloud console project, the UiPath the GSuite Application Scope for a ServiceAccountKey authentification should look something like this:

@marian.platonov Thank you very much!!

This is how my property panel looks like.
I gave JSON key type. is it not possible to read mail using JSON??
or the issue might be due to roles assigned while creating service accounts?
Precondition not met[400] is the error i get.
Kindly advise

Please read carefully this documentation and configure the Properties of the GSuite Application Scope:

When you use UiPath Apps, you allow UiPath Robots to access the data inside your Google mail account. Subsequently, you allow UiPath Robots to manipulate the data solely in accordance with your instructions. UiPath will never access, store, or process in any manner the data that you manipulate with the use of UiPath Robots and will not allow for the Robots to be used outside the user’s instructions. UiPath’s use of information received from Google APIs will adhere to the Google API Services User Data Policy, including the Limited Use requirements.
You can see the full UiPath Privacy Policy for more information.

Then take a look at these properties for a Service Account Key:

Service Account Key

The property fields below are required only if your AuthenticationType value is ServiceAccountKey.

  • HasDomainWideAccess - If checked, the activity grants domain-wide access to the service account.
  • KeyPath - The path to the service account key file. This property supports String variables and string formatted values. The creation of a service account on the Google Cloud Platform generates a key file for download.
  • KeyType - A drop-down list that specifies the service account type according to the key file.The available property values are JSON or P12. For a P12 service account type, the Password and ServiceAccountEmail properties are required.
  • Password - The password for the service account. This property supports String variables and string formatted values and is required only if your KeyType value is P12.
  • ServiceAccountEmail - The auto-generated email address for the service account. This property supports String variables and string formatted values and is required only if your KeyType value is P12.
  • UserEmail - If HasDomainWideAccess is checked, the service account impersonates a user from the domain; use this field to enter the impersonated user’s email address.

@marian.platonov Thank you somuch. While creating Service Account what is the role and permission has to be enabled for accessing gmail accounts?

1 Like

Get Mail Messages: Error:“unauthorized_client”, Description:“Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested.”, Uri:“”

please comment on this

“client is unauthorized to retrieve access tokens using this method”.

Means exactly that. The client you have set up on Google developer console is either not a service account client or the code you are using is not meant for a service account client.

Make sure that the client you created on the google developer console is a service account client.

Make sure that you enabled the Gmail API in your project.

There are a couple of things you need to keep in mind:

  • Service Account can not be used with Gmail account, only with Gsuite (the paid Google services). This is because you need to “Delegate domain-wide access” in order for the Service Account to work, and this is not possible in Gmail.

  • If using GSuite you should follow the steps below:

  1. Enable Gmail API (only follow “enable APIs” from here, not “create credentials”. That will be explained more clearly in links 2 and 3.)

  2. Create Service Account (and download JSON keyfile) Using OAuth 2.0 for Server to Server Applications | Google Identity

  3. Enable Domain Wide Delegation for the Service Account, copy the Client ID

  4. Ask your Gsuite admin to allow the Domain Wide Delegation (send him the Client ID). It took me a while to find out that you have to enable Domain Wide Delegation both on your own end, as well as on the Admin side. Uso de OAuth 2.0 para aplicaciones de servidor a servidor

  5. I think this is it, but I vaguely remember having to set up the Oauth consent screen in GCP as well. If you have to configure the consent screen, just put Application Type = public, make up a name, and put your e-mail as Support Email. The consent screen won’t be shown, as you’re using a Service Account which is pre-authenticated.

Reference: GSuite - Gmail Activity Unauthorized client error - #30 by Jeroen

Please let me know if this was of any help, and if you managed to get through.

1 Like

@marian.platonov Thank you somuch. That really helps!!
So to conclude my understanding, Inorder to access any Gmail account using ServiceAccount in Gsuite we should make sure the Service account created has been provided with certain permissions by admin
1)Gmail API Enable
2)Enable Domain Wide Delegation on both ends(Admin and in Gsuite Activity “Has Domainwide Access=True”)


1 Like

Hi @marian.platonov One More Question
I am able to read Google spreadsheet using the same service Account. I am not able to make it work for the “Get Mail Message” Activity. Is that something i am missing out? or is it due to permissions missing on “delegation and GMail API”.
Please Advise


For Google Drive, Excel it will work, but for email, it will not work due to not Enabling Domain Wide Delegation for the Service Account and configuring it.

You may reconsider other approaches for Gmail automation without GSuite in this case.

@marian.platonov Thank you very much!! That helps a lot!!

Hi @marian.platonov
Is it possible to use app script via Service account key Authentication ?

I came across this context

where it says “AppScript API doesnot work with Service Accounts”
Please advise

Based on the official documentation from Google (that you found already by the way), they are stating that this will not work.

@marian.platonov Thank you for the confirmation.