Gmail
The Carbon Connect enabledIntegrations
value for Gmail is GMAIL
Authorization Type
Carbon uses OAuth 2.0 to connect to Gmail.
Authorization Flow
After the user logs into their Gmail account, Carbon auto-syncs all emails based on the filters set via our API.
Configuration
Custom OAuth Credentials
- Go to
APIs and Services
>Enabled APIs and Services
in your Google Cloud console, then click on the button titledENABLE APIS AND SERVICES
and enableGmail API
. - Then create an
OAuth Client ID
in theCredentials section
underGmail API
. SelectWeb Application
as the Application type and give it an identifiable name for your reference.
- Add https://api.carbon.ai as the
Authorized JS origin
and https://api.carbon.ai/integrations/gmail as anAuthorized redirect URI
. You can also opt to use a custom CNAME record pointing to https://api.carbon.ai for theAuthorized JS Origin
andAuthorized redirect URI
. However, for theAuthorized redirect URI
the domain paths must still be/integrations/gmail
.
- Save the credentials. Download the credentials.json file once you save the OAuth Client ID data and share the file with Carbon.
- Configure your consent screen in the OAuth Consent Screen. Provide your App name, support email address, and brand logo. Add carbon.ai (or your custom CNAME) to
Authorized domain
.
- Click on
Add or Remove Scopes
button to add the following scopes:/auth/gmail.readonly
- If you wish to add test users, you can do so. These users will not see the “App is unverified” notification. Other users will see this alert.
- Click
Publish App
to make this app available to your end-users.
Synchronization
After successfully connecting your Gmail account, you gain the ability to selectively sync emails by utilizing the filters
parameter via the /integrations/gmail/sync
endpoint. This parameter operates as a JSON object comprising key-value pairs, supporting both AND and OR operations. Presently, our system accommodates a specific set of keys as detailed below:
label
Represents predefined Gmail labels such as “Important” or custom labels created by the user.
after
Accepts a date in the format YYYY/mm/dd (e.g., 2023/12/31), enabling the retrieval of emails after a specified date.
before
Accepts a date in the format YYYY/mm/dd (e.g., 2023/12/31), enabling the retrieval of emails before a specified date.
is
Supports values like starred
, important
, snoozed
, and unread
to filter emails based on these attributes.
to
Supports an email (email@address.com
) as a string to which the email was sent.
from
Supports an email (email@address.com
) as a string from which the email was sent.
in
Supports the value sent
as a string to filter for all emails sent from an account.
has
Supports the value attachment
as a string to filter for all emails sent from an account.
It’s crucial to adhere to the specified keys and values within the JSON object. Usage of keys or values outside this defined scope might result in unexpected behavior.
An example of a basic query with filters, which lists all emails that have the label Test
:
You can use AND and OR operation as follows.
This setup ensures the retrieval of emails dated after January 7th that satisfy either of the two conditions: having the label “Personal” or being marked as ‘starred’. The structure allows for the effective use of AND and OR operations to filter emails based on the defined criteria.
You can use the resync_file
API endpoint to programmatically resync specific Gmail emails. To delete specific emails from Carbon, you can use the delete_files
endpoint directly.
To sync Gmail files on a 24-hour schedule (more frequent schedules available upon request), you can use the /update_users
endpoint. This endpoint allows organizations to customize syncing settings according to their requirements, with the option to enable syncing for all data sources using the string ‘ALL’. It’s important to note that each request supports up to 100 customer IDs.
Here’s an example illustrating how to automatically enable syncing for updated Gmail content for specified users: