Skip to content

Gmail

Access and manage your Gmail emails through the Gmail API.

This source provides a single flexible api_gmail tool that accepts:

  • path: API endpoint (e.g., “/gmail/v1/users/me/messages”)
  • method: HTTP method (GET, POST, etc.)
  • params: Request body or query parameters
EndpointMethodDescription
/gmail/v1/users/me/messagesGETList messages (use q param for search)
/gmail/v1/users/me/messages/{id}GETGet message by ID
/gmail/v1/users/me/draftsPOSTCreate draft
/gmail/v1/users/me/messages/{id}/trashPOSTTrash message

Common search operators:

  • from:sender@example.com - Messages from specific sender
  • to:recipient@example.com - Messages to specific recipient
  • subject:keyword - Messages with keyword in subject
  • is:unread - Unread messages
  • has:attachment - Messages with attachments
  • after:2024/01/01 - Messages after a date
  • in:inbox - Messages in inbox

Combine operators: from:john@example.com after:2024/01/01 has:attachment

  • Privacy: This source accesses personal email. All data remains local.
  • Trashing: ALWAYS ask for explicit user permission before trashing emails.
  • Drafts: Draft emails are saved but NOT sent automatically.

Required config.json:

{
"name": "Gmail",
"slug": "gmail",
"enabled": true,
"provider": "google",
"type": "api",
"api": {
"baseUrl": "https://gmail.googleapis.com/",
"authType": "bearer",
"googleService": "gmail",
"googleOAuthClientId": "your-client-id.apps.googleusercontent.com",
"googleOAuthClientSecret": "your-client-secret"
},
"iconUrl": "https://mail.google.com"
}

See Google OAuth Setup for instructions on creating OAuth credentials, then use source_google_oauth_trigger to start the OAuth flow.

If you authenticate through WebUI / headless browser access, use a Web application Google OAuth client and register this exact redirect URI:

  • https://thecraftagents.com/auth/callback

“Gmail API has not been used in project” error

Section titled ““Gmail API has not been used in project” error”

The Gmail API needs to be enabled in your Google Cloud project:

  1. Visit the Gmail API page
  2. Click Enable
  3. Wait 1-2 minutes for changes to propagate

“Google OAuth credentials not configured” error

Section titled ““Google OAuth credentials not configured” error”

Add your OAuth client ID and secret to the source’s config.json under the api section.

  • 250 quota units per user per second
  • Most read operations cost 1-5 units
  • Avoid rapid sequential requests