DEV

Gmail

Gmail Connection

Put Gmail to Work with @Human Automations and @Human Agents

The Gmail Connection documents all Triggers, Actions and Query Operations available for creating automations via the Gmail API.

What can you do with the Gmail Connection?

  • Connect to the Gmail API in a few clicks

  • Use the related Gmail Operations (see below) in @Human Automations or @Human Agents

Trigger Operations

Email Received

Triggers on: emails/emailReceived

Triggered when a new email is received in the user's Gmail inbox.

Label Created

Triggers on: labels/labelCreated

Triggered when a new label is created in the user's Gmail account.

Draft Created

Triggers on: drafts/draftCreated

Triggered when a new draft is created in the user's Gmail account.

Action Operations

Action: Add Label to Email

Action: Delete Email

Action: Create Draft Reply

Action: Send Email

Action: Remove Label From Conversation

Action: Archive Email

Action: Create Draft

Action: Create Label

Action: Remove Label From Email

Action: Reply to Email

Query Operations

Query: Get Attachment by Filename

Query: Find or Send Email

Query: Find Email

Example link

Obtaining Access Credentials

This guide covers setting up Gmail for server-side (non-interactive) use via a Google service account with Domain-Wide Delegation (DWD). This allows @Human to send email as any user in your Google Workspace domain without requiring individual OAuth consent screens.

Important: Domain-Wide Delegation is only available for Google Workspace organisations (paid). It is not supported on personal Gmail accounts.

1. Google Cloud — Enable the Gmail API

  • Go to Google Cloud Console and select (or create) your project.

  • Navigate to APIs & Services > Library.

  • Search for Gmail API and click Enable.

2. Google Cloud — Create a Service Account

  • Navigate to IAM & Admin > Service Accounts.

  • Click + Create Service Account.

  • Fill in a name, e.g. at-human-gmail, and click Create and Continue.

  • Skip role assignment (roles are not needed for DWD) → click Done.

  • Copy the Unique ID (Client ID) of the newly created service account — you will need it in Step 3.

3. Google Workspace Admin — Grant Domain-Wide Delegation

  • Go to Google Workspace Admin ConsoleSecurity > API controls > Domain-wide Delegation. Direct link: https://admin.google.com/ac/owl/domainwidedelegation

  • Click + Add new.

  • Client ID: paste the service account's Unique ID (Client ID) from Step 2.

  • OAuth Scopes: add the following scope (grants full Gmail access):

    Use the full https://mail.google.com/ scope. The broader https://www.googleapis.com will not work for Gmail API calls.

  • Click Authorize.

Propagation delay: DWD grants can take up to 15 minutes to propagate before they become effective.

4. Google Cloud — Generate a Service Account Key

  • Go back to IAM & Admin > Service Accounts in Google Cloud Console.

  • Click on your service account (at-human-gmail).

  • Go to the Keys tab → Add Key > Create new key.

  • Choose JSON format → click Create.

  • The key file downloads automatically. Store it securely — it cannot be re-downloaded.

Configuring Webhooks

1. Enable Cloud Pub/Sub API

  • Select or create a project.

  • Navigate to APIs & Services > Library.

  • Search for "Cloud Pub/Sub API" and enable it.

2. Create a Pub/Sub Topic

  • Navigate to Pub/Sub > Topics.

  • Click CREATE TOPIC.

  • Enter a Topic ID (e.g., gmail-notifications).

  • Click CREATE.

3. Configure Permissions

  • In the topic details, click SHOW INFO PANEL then ADD PRINCIPAL.

  • Enter gmail-api-push@system.gserviceaccount.com.

  • Assign the "Pub/Sub Publisher" role.

  • Click SAVE.

4. Create a Push Subscription

  • Navigate to Pub/Sub > Subscriptions.

  • Click CREATE SUBSCRIPTION.

  • Enter a Subscription ID.

  • Select the Topic created in step 2.

  • Set Delivery type to Push.

  • Enter your Endpoint URL.

  • Click CREATE.

5. Register the Mailbox for Notifications

  • Call the Gmail API users.watch endpoint.

  • In the request body, provide the topicName: projects/{PROJECT_ID}/topics/{TOPIC_NAME}.

  • (Optional) Specify labelIds or labelFilterAction.

Code (Apache v2.0): Service Connectivity and Metadata

Code (Apache v2.0): List of External Resources and Internal Mapping

Last updated