Skip to main content
Gmail REST API access for reading, composing, sending, and managing email on behalf of a connected user. Use when an agent needs to read inbox state, draft and send messages, manage labels, or work with threads in a user’s Gmail account. Routes through Pipedream Connect — the user sees one Google consent screen on connect that says “Pipedream wants access” (Pipedream owns the verified OAuth client). Differs from raw SMTP because all calls go through the official Gmail REST API with full structured-data access (labels, threads, attachments metadata). 10 example endpoints available through Lava’s AI Gateway. See the Gmail API docs for full documentation.
This provider requires your own credentials — connect your API key or OAuth account before use.
This is a catch-all provider — any valid URL under https://gmail.googleapis.com is supported. Gmail REST API endpoints. Construct URLs as https://gmail.googleapis.com/gmail/v1/{path}. Authentication is brokered through Pipedream Connect — the end-user sees a single “Pipedream wants to access your Google Account” consent screen on connect. Common roots: users/me/profile, users/me/messages, users/me/threads, users/me/labels, users/me/drafts. When composing mail (messages.send or drafts.create), set raw to the plaintext RFC 2822 message — Lava base64url-encodes it for you, so do NOT pre-encode — and use an HTML body (Content-Type: text/html): a bare text/plain body hard-wraps at ~78 columns on send and shows premature mid-sentence line breaks. See https://developers.google.com/gmail/api/reference/rest for full reference. The endpoints below are curated examples.

Endpoints

Get the connected Gmail account’s profile (email address, total messages count). Use this as a cheap auth probe after connect — confirms the OAuth grant is healthy without enumerating messages.

GET https://gmail.googleapis.com/gmail/v1/users/me/profile — Free
const data = await lava.gateway('https://gmail.googleapis.com/gmail/v1/users/me/profile', { method: 'GET' });

List messages in the user’s mailbox, optionally filtered by a Gmail search query (q param). Returns lightweight references — use messages.get to fetch full content. Supports labelIds, maxResults, pageToken.

GET https://gmail.googleapis.com/gmail/v1/users/me/messages?q=is%3Aunread&maxResults=10 — Free
const data = await lava.gateway('https://gmail.googleapis.com/gmail/v1/users/me/messages?q=is%3Aunread&maxResults=10', { method: 'GET' });

Get a single message by id. Use format=metadata for cheap header-only reads, format=full for the complete body. Recommend format=metadata + metadataHeaders=Subject,From,To,Date for inbox triage workflows.

GET https://gmail.googleapis.com/gmail/v1/users/me/messages/18e2f5d8b1a2c3d4?format=metadata&metadataHeaders=Subject&metadataHeaders=From — Free
const data = await lava.gateway('https://gmail.googleapis.com/gmail/v1/users/me/messages/18e2f5d8b1a2c3d4?format=metadata&metadataHeaders=Subject&metadataHeaders=From', { method: 'GET' });

Send an email on behalf of the connected user. Set raw to the plaintext RFC 2822 message (To/Subject/… headers, a blank line, then the body) — Lava base64url-encodes it for you, so do NOT pre-encode. Send the body as HTML: set MIME-Version: 1.0 and Content-Type: text/html; charset="UTF-8", and use <p>/<br> for line structure. A bare text/plain body is hard-wrapped at ~78 columns on send — Gmail inserts physical line breaks to satisfy RFC 5322 line limits, which surface as premature mid-sentence breaks in the delivered mail. HTML reflows to the reader’s window and avoids this; multipart/alternative (plain + HTML) is the most compatible. The connected account must have send permission (Pipedream’s default Gmail scopes include gmail.send).

POST https://gmail.googleapis.com/gmail/v1/users/me/messages/send — Free
const data = await lava.gateway('https://gmail.googleapis.com/gmail/v1/users/me/messages/send', {
  body: {
"raw": "To: recipient@example.com\r\nSubject: Hello\r\nMIME-Version: 1.0\r\nContent-Type: text/html; charset=\"UTF-8\"\r\n\r\n<p>Hi there,</p><p>Sending this as HTML so the body reflows to the reader's window instead of hard-wrapping at ~78 columns.</p><p>Best,<br>Lava</p>"
},
});

Create a draft (does NOT send). Body is { "message": { "raw": <plaintext RFC 2822 message> } } — Lava base64url-encodes raw for you, so do NOT pre-encode. For a threaded reply, put threadId next to raw in message and include In-Reply-To and References headers (the original Message-ID, from messages.get) in the raw so Gmail threads it. Same HTML-body guidance as messages.send.

POST https://gmail.googleapis.com/gmail/v1/users/me/drafts — Free
const data = await lava.gateway('https://gmail.googleapis.com/gmail/v1/users/me/drafts', {
  body: {
"message": {
  "raw": "To: recipient@example.com\r\nSubject: Hello\r\nMIME-Version: 1.0\r\nContent-Type: text/html; charset=\"UTF-8\"\r\n\r\n<p>Hi there,</p><p>This is a draft for review.</p><p>Best,<br>Lava</p>"
}
},
});

Add or remove labels on a message. Common use: mark as read by removing UNREAD; archive by removing INBOX; star by adding STARRED.

POST https://gmail.googleapis.com/gmail/v1/users/me/messages/18e2f5d8b1a2c3d4/modify — Free
const data = await lava.gateway('https://gmail.googleapis.com/gmail/v1/users/me/messages/18e2f5d8b1a2c3d4/modify', { body: {"removeLabelIds":["UNREAD"]} });

List threads in the user’s mailbox. Threads bundle reply chains together — prefer threads.list over messages.list when an agent needs to reason about conversations rather than individual messages.

GET https://gmail.googleapis.com/gmail/v1/users/me/threads?q=from%3Aboss%40example.com&maxResults=5 — Free
const data = await lava.gateway('https://gmail.googleapis.com/gmail/v1/users/me/threads?q=from%3Aboss%40example.com&maxResults=5', { method: 'GET' });

Get a full thread (all messages in the reply chain). Format options match messages.get: metadata for headers, full for bodies.

GET https://gmail.googleapis.com/gmail/v1/users/me/threads/18e2f5d8b1a2c3d4 — Free
const data = await lava.gateway('https://gmail.googleapis.com/gmail/v1/users/me/threads/18e2f5d8b1a2c3d4', { method: 'GET' });

List the user’s labels — both system labels (INBOX, UNREAD, STARRED, IMPORTANT, etc.) and any custom labels the user has created. Returns ID + name for each; agents need IDs (not names) for modify operations.

GET https://gmail.googleapis.com/gmail/v1/users/me/labels — Free
const data = await lava.gateway('https://gmail.googleapis.com/gmail/v1/users/me/labels', { method: 'GET' });
POST https://gmail.googleapis.com/gmail/v1/users/me/labels — Free
const data = await lava.gateway('https://gmail.googleapis.com/gmail/v1/users/me/labels', {
  body: {
"name": "Lava/Processed",
"labelListVisibility": "labelShow",
"messageListVisibility": "show"
},
});

Next Steps

All Providers

Browse all supported AI providers

Forward Proxy

Learn how to construct proxy URLs and authenticate requests