This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Configuring Gmail Operations
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.
<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 theconnectors/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.
- Enter ConnectGmailAPI as the name of the project and click Create.
- Click Create credentials and click OAuth client ID.
- Click Configure consent screen in the next screen.
- Enter ConnectGmailAPI as the Product Name, and click Save.
Enter the following details in the Create OAuth client ID screen and click Create.
Field Value Application type Web application Name ConnectGmailClient Authorized redirect URIs (to get the code to request an AccessToken call to theGmail API.) https://developers.google.com/oauthplayground
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 except the gmail.metadata scope under it, and click Authorize APIs.
- 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.
Now that you have connected with Gmail REST API, use the information in the following topics to perform various operations with the Gmail connector.