To use the Gmail connector, add the <gmail.init>
element in your configuration before carrying out any other Gmail operations. The Gmail API uses OAuth2 authentication with Tokens. For more information on authentication, go to Authorizing Your App with Gmail.
Code Block |
---|
|
<gmail.init>
<userId>{$ctx:userId}</userId>
<refreshToken>{$ctx:refreshToken}</refreshToken>
<clientSecret>{$ctx:clientSecret}</clientSecret>
<clientId>{$ctx:clientId}</clientId>
<registryPath>{$ctx:registryPath}</registryPath>
<accessToken>{$ctx:accessToken}</accessToken>
<apiUrl>{$ctx:apiUrl}</apiUrl>
</gmail.init> |
Properties
accessToken
: Value of the Access Token to access the Gmail REST API.
refreshToken
: Value of the Refresh Token, which generates a new Access Token when the previous one gets expired.
apiUrl
: The API URL of Gmail (https://www.googleapis.com/gmail).
userId
: User mail ID.
clientSecret
: Value of the Client Secret you obtained when you registered your application with the Gmail API.
-
clientId
: Value of the Client ID you obtained when you registered your application with Gmail API. -
registryPath
: Registry Path of the connector where the Access Token will be stored. (If not provided, the connector stores the Access Token in the connectors/Gmail/accessToken
Registry Path).
Creating the Client ID and Client Secret
Follow the steps below to obtain a Client ID and Client Secret for your Gmail account.
- Navigate to Google API Credentials and select your Gmail account to log in using that, to create an App to connect with the Gmail API.
- Click Select a Project and click NEW PROJECT, to create a project. Alternatively, you can use an existing project.
Image Modified
- Enter ConnectGmailAPI as the name of the project and click Create.
Image Modified
- Click Create credentials and click OAuth client ID.
Image Modified
- Click Configure consent screen in the next screen.
Image Modified
- Enter ConnectGmailAPI as the Product Name, and click Save.
Image Modified Enter the following details in the Create OAuth client ID screen and click Create.
You view the Client ID and Client Secret you generated.
- Copy and keep the two links saved into a text file as you will need those for the next steps, and click OK.
- Click Library on the side menu, search for Gmail API and click on it.
- Click Enable to enable the Gmail API.
- Obtaing the Access Token and Refresh Token
Follow the steps below to automatically refresh the expired AccessToken and Refresh Token for your Gmail account, when connecting to Google API.
- Navigate to the OAuth 2.0 Playground and click OAuth 2.0 Configuration button.
- Select Use your own OAuth credentials, enter the Client ID and Client secret you created and click Close.
- Under Step 1, select Gmail API v1 from the list of APIs, select all the scopes listed under except the gmail.metadata scope under it, and click Authorize APIs.
Image RemovedImage Added - Select you Gmail account and click Allow, to grant the required permissions.
- Under Step 2, click Exchange authorization code for tokens to generate an display the Access Token and Refresh Token.
...