Create Calendar
This API endpoint is triggered by the extension interface to create a new calendar on Google calendar when selecting a calendar to attach with a Scrims calendar.
Endpoint
POST /google/calendars HTTP/1.1
Host: api.atomcal.com/api/v2
Content-Type: application/x-www-form-urlencoded
Triggered by: Extension interface
Authentication: security.verifyAuthToken
Query: req.query.account_id, req.query.scrims_calendar_id
If a calendar with similar title is found it doesn't create a new one but it does attach the Scrims calendar with this calendar and synchronize all events.
Example Responses
200 (successful operation)
res.status(200).send({ calendars });
400 (bad response)
Boom.badRequest(errorMessage)
Implementation details
Create Google calendar
- Read the Scrims calendar from Scrims API using scrims_calendar_id query param passed by the extension ui.
- Using the account_id query param obtain the Google calendar authentication code to fetch all the Google calendars.
- If the Scrims calendar (by title) is not found on Google calendar, create a new one using create calendar URI.
let calendarsUri = `https://www.googleapis.com/calendar/v3/calendars`;
let gotGoogleCalendar = await got.post(calendarsUri, {
headers: { Authorization, "Content-Type": "application/json" },
body: JSON.stringify({ summary: localCalendar.title || "No title" }),
});
Synchronize the calendar events
Finally synchronize Scrims calendar events to this Google calendar and Google calendar events to this Scrims calendar using appropriate endpoints.
`${baseUrl}/api/v2/calendars/${googleCalendar.atomcal_calendar_id}/events`
`https://www.googleapis.com/calendar/v3/calendars/${calendarIdEncoded}/events`
Register notification channels
Register notification channels for Google calendar and Scrims calendar.
Return all Google calendars
Finally read all the google calendars using the member id obtained from the token authenticator service and return all saved Google calendars.
Edge cases
Make sure similar calendar (by title) does not exist on Google calendar. Incase it does attach the Scrims calendar with this already saved calendar.
In case Google account authentication code is expired or refresh token is malformed it throws a bad request error.