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.

init
<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.

  1. 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.
  2. Click Select a Project and click NEW PROJECT, to create a project. Alternatively, you can use an existing project.

  3. Enter ConnectGmailAPI as the name of the project and click Create.

  4. Click Create credentials and click OAuth client ID.

  5. Click Configure consent screen in the next screen.

  6. Enter ConnectGmailAPI as the Product Name, and click Save.
  7. Enter the following details in the Create OAuth client ID screen and click Create.

    FieldValue
    Application typeWeb application
    NameConnectGmailClient
    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. 

  8.  Copy and keep the two links saved into a text file as you will need those for the next steps, and click OK.
  9. Click Library on the side menu, search for Gmail API and click on it.
  10. Click Enable to enable the Gmail API.
  11. 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.

  1. Navigate to the OAuth 2.0 Playground and click OAuth 2.0 Configuration button.

  2. Select Use your own OAuth credentials, enter the Client ID and Client secret you created and click Close.
  3. 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.
  4. Select you Gmail account and click Allow, to grant the required permissions.
  5. 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.