Gmail (Apps step)

Updated Nov 23, 2026
DataMagik Automate

Gmail

Finds and reads messages in a Gmail mailbox (read only).

Use it to act on mail that arrives in a Gmail mailbox: pick up purchase orders a customer emails in, check a shared inbox for supplier notices, or count unread requests for a report. It only reads; DataMagik sends email itself with the Send Email step.

Beta. This step has not yet been checked against a live Gmail account, so treat its first runs as a test, and tell us if an operation does not answer as described.

Find it in the workflow editor's palette under Apps. See Apps steps for what every Apps step has in common.

Set it up

  1. In Google Cloud Console, choose or create a project, open APIs & Services › Library and enable the Gmail API.
  2. Open APIs & Services › OAuth consent screen and set it up; for a Google Workspace company choose Internal. Reading mail is a restricted scope, so an External app needs Google's verification, and one left in Testing must list the signing-in account as a test user and ends its sign-in after 7 days.
  3. Open APIs & Services › Credentials › Create credentials › OAuth client ID, choose Web application, and keep the client ID and client secret for the DataMagik credential. The same client can serve Google Sheets and Google Drive too.
  4. Add gmail.googleapis.com to Allowed Domains in the workflow's Script settings.

Credential: An OAuth 2.0 credential for your Google OAuth client, connected with the Gmail account whose mail the step reads.

Signing in with OAuth 2.0

Grant typeSign in with the provider (authorization code). Save the credential, then click Connect on it.
Sign-in (authorization) URLhttps://accounts.google.com/o/oauth2/v2/auth
Token URLhttps://oauth2.googleapis.com/token
Scopehttps://www.googleapis.com/auth/gmail.readonly

Register the Redirect URI the credential form shows in the provider's app settings.

Create the OAuth client in Google Cloud Console as type Web application, enable the Gmail API in the same project, and add the Redirect URI the DataMagik credential shows to the client's Authorized redirect URIs.

Hosts it calls: gmail.googleapis.com

Operations

OperationWhat it does
Message › ListFinds messages with a Gmail search query, newest first, following every page up to the step's page limit.
Message › GetReads one message by its id.

Message › List

Finds messages with a Gmail search query, newest first, following every page up to the step's page limit.

Calls GET /messages. Follows the pages, up to Most pages (10 unless you change it).

FieldRequiredWhat to put
QueryNoA Gmail search, as typed in Gmail's search box. Leave empty for every message. For example from:orders@customer.com is:unread.
LabelNoOnly messages with this label id, such as INBOX, UNREAD or SENT; a label you made has an id such as Label_12. For example INBOX.
Page sizeNoMessages per request (Gmail's limit is 500). For example 100.

What comes out: One item per message with only {{ $json.id }} and {{ $json.threadId }}; use Get on {{ $json.id }} for the subject, sender and content. No messages means no items.

Example: List subject:"Purchase Order" newer_than:1d to find today's emailed orders before reading each one.

Message › Get

Reads one message by its id.

Calls GET /messages/{id}.

FieldRequiredWhat to put
Message IDYesThe message's id, {{ $json.id }} from List. For example {{ $json.id }}.
FormatNoHow much of the message to read: Metadata gives the headers (subject, from, date) and a short snippet; Full adds the body; Minimal gives only ids, labels and the snippet. One of: Metadata (headers and snippet), Full (headers and body), Minimal (ids and labels).

What comes out: One item: the message, with {{ $json.id }}, {{ $json.threadId }}, {{ $json.labelIds }}, {{ $json.snippet }} (the first words of the text), {{ $json.internalDate }} (when Gmail received it, in milliseconds since 1970, as text) and, for Metadata and Full, {{ $json.payload.headers }}, a list of { name, value } headers such as Subject and From. Full adds the body, base64url-encoded, in {{ $json.payload.body.data }}, or in {{ $json.payload.parts }} for a message with several parts.

Example: Get {{ $json.id }} in Metadata format and take the Subject header to find the PO number for the order lookup.

Trigger: Gmail: New Items

Under Triggers in the palette. It looks at Gmail on a schedule (every 15 minutes unless you change Look every) with one of these operations: Message › List, and starts the workflow with the items it has not seen on an earlier look, one item each. Saving the workflow sets up the schedule.

  • New means: not seen before, by the item's id (or the field you name in Item field), or newer than the newest one last time, by a date or increasing number.
  • On the first run it only remembers what is there, unless you choose Start with everything.
  • Test runs show what would be new without remembering it. It remembers the last 5000 ids, so filter the list to keep it shorter than that.

Example

A schedule runs every 15 minutes; Gmail › List messages with the query from:orders@customer.com newer_than:1d finds new orders, and Gmail › Get reads each one's subject and sender for a Jira ticket.

Tips

  • The query uses Gmail's search syntax, the same as the search box: from:, to:, subject:, is:unread, has:attachment, newer_than:2d, after:2026/11/01.
  • List gives only each message's id and thread id; add a Get step on {{ $json.id }} to read the subject, sender and text.
  • Metadata format is enough for the subject, sender and date: they are in {{ $json.payload.headers }}, a list of name and value pairs. Full also gives the message body, base64url-encoded, in payload.body.data, or in payload.parts for a message with several parts (text and HTML, attachments).
  • The step cannot send, label or delete mail; use the Send Email step to send.

Settings every Apps step has

  • More query parameters: any query parameter the fields do not offer, sent as is.
  • More body fields: a JSON object merged into the request body; nested objects merge, other values replace.
  • Most requests per second: spaces the calls out for rate limits. A "too many requests" (429) answer is retried after the wait the API asks for.
  • Most pages: for operations that follow pages, the most pages to fetch (10 unless you change it, up to 100). The run warns when it stops with more to get.
  • Fail on a non-2xx response: on by default. Turn it off to handle errors yourself.

Gmail's own API documentation: https://developers.google.com/gmail/api/reference/rest

Was this page helpful?