Author: Harsha J
The below article talks about configuring google calendar API version V1.1.5 in anypoint studio and retrieving access and refresh tokens.
Before starting with the Studio let us setup Google calendar API
STEP 1: Setting up Google Calendar API
- Click on Select a project > New project > Enter a project name > Create
- Again click on Select a project > select the created project
- Search Calendar API > Google calendar API > Enable
- Click on OAuth consent screen on the left side > External > create
- Fill out all the mandatory fields
- In scopes click on ADD or Remove Scopes > select first three scopes then search Google calendar API > update
- Add test users by clicking Add users (can add multiple mail Ids)
- Click on Credentials on the left side
- Create credentials > OAuth client ID > select web application
- Add Authorized redirect URIs > Create
- Save or download the Client Id and secret in JSON format
STEP 2: configuring API in Anypoint studio
- Create a Mule application and import the Google calendar connector from the exchange
- Go to global elements and create a Google calendar connector configuration
- Provide Client Id and Client secret in Consumer Key and secret
Set the following fields
Base URI = “https://www.googleapis.com/calendar/v3”
Access token Url = “https://accounts.google.com/o/oauth2/token”
Authorization Url = “https://accounts.google.com/o/oauth2/auth”
scopes=”https://www.googleapis.com/auth/calendar”
callbackPath=”/callback” authorizePath=”/authorize”
externalCallbackUrl=”http://localhost:8081/callback”
- Create an object store configuration and add in oauthStore config
- Create a flow with listener, Retrieve all and Transform message
- Select the same object store configuration used in Calendar configuration
- Set transform message output as application/json
%dw 2.0
output application/json
—
Payload
- Run the project > go to Chrome and search “http://localhost:8081/authorize”
Before choosing the account go to end of the link and include
“&access_type=offline”
Doing this will retrieve access token along with refresh token
Note : Refresh token will only work in localhost
- Choose the gmail account and the token will be retrieved
- Go to postman and enter the path of objectStore flow previously created
- Using the Event insert component to schedule meetings in Google Calendar
Drag an Event insert component from the mule palette and configure it as shown below
Set payload as shown :
%dw 2.0
output application/json
—
{
“summary”: “Interview Schedule”,
“description”: write(vars.htmlCode,’application/xml’) as String replace /([“\n”])/ with “”,
“guestsCanSeeOtherGuests”: false,
“guestsCanInviteOthers”: false,
“start”: {
“dateTime”: payload.startDateTime,
“timeZone”: “Asia/Kolkata”
},
“end”: {
“dateTime”: payload.endDateTime,
“timeZone”: “Asia/Kolkata”
},
“attendees”: payload.attendees,
“reminders”: {
“useDefault”: true
},
“conferenceData”: {
“createRequest”: {
“requestId”: “sample123”,
“conferenceSolutionKey”: {
“type”: “hangoutsMeet”
}
}
}
}
By doing this you will be successfully able to schedule a meeting with the google meet link generated automatically