- Create new create-google-meet-event edge function - Use service account authentication (no OAuth needed) - Add google_service_account_json field to platform_settings - Add admin UI for service account JSON configuration - Include test connection button in Integrasi tab - Add comprehensive setup documentation - Keep n8n workflows as alternative option Features: - Direct Google Calendar API integration - JWT authentication with service account - Auto-create Google Meet links - No external dependencies needed - Simple configuration via admin panel 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
6.0 KiB
6.0 KiB
Google Calendar Integration with Service Account
Overview
Using a Service Account to integrate Google Calendar API without OAuth user consent.
Setup Instructions
1. Create Service Account in Google Cloud Console
- Go to Google Cloud Console
- Create a new project or select existing one
- Navigate to IAM & Admin → Service Accounts
- Click Create Service Account
- Fill in details:
- Name:
access-hub-calendar - Description:
Service account for Access Hub calendar integration
- Name:
- Click Create and Continue
- Skip granting roles (not needed for Calendar API)
- Click Done
2. Enable Google Calendar API
- In Google Cloud Console, go to APIs & Services → Library
- Search for "Google Calendar API"
- Click on it and press Enable
3. Create Service Account Key
- Go to your service account page
- Click on the Keys tab
- Click Add Key → Create New Key
- Select JSON format
- Click Create - this will download a JSON file with credentials
- Keep this file secure - it contains your private key
The JSON file looks like:
{
"type": "service_account",
"project_id": "your-project-id",
"private_key_id": "...",
"private_key": "-----BEGIN PRIVATE KEY-----\n...",
"client_email": "access-hub-calendar@your-project-id.iam.gserviceaccount.com",
"client_id": "...",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token"
}
4. Share Calendar with Service Account
- Go to Google Calendar
- Find the calendar you want to use (e.g., your main calendar)
- Click the three dots next to the calendar name
- Select Settings and sharing
- Scroll to Share with specific people
- Click + Add people
- Enter the service account email:
access-hub-calendar@your-project-id.iam.gserviceaccount.com - Set permissions to Editor (can make changes to events)
- Click Send (ignore the email notification)
5. Get Calendar ID
- For your primary calendar:
your-email@gmail.com - For other calendars: Go to Calendar Settings → Integrate calendar → Calendar ID
n8n Workflow Configuration
Option A: Using Google Calendar Node
- Add a Google Calendar node to your workflow
- Select Service Account as authentication
- Paste the entire Service Account JSON content
- Select the calendar ID
- Choose operation: Create Event
Option B: Using HTTP Request Node (More Control)
// In n8n Code node or HTTP Request node
const { GoogleToken } = require('gtoken');
const { google } = require('googleapis');
// Service account credentials
const serviceAccount = {
type: 'service_account',
project_id: 'your-project-id',
private_key_id: '...',
private_key: '-----BEGIN PRIVATE KEY-----\n...',
client_email: 'access-hub-calendar@your-project-id.iam.gserviceaccount.com',
client_id: '...',
};
// Create JWT client
const jwtClient = new google.auth.JWT(
serviceAccount.client_email,
null,
serviceAccount.private_key,
['https://www.googleapis.com/auth/calendar']
);
// Authorize and create event
jwtClient.authorize(async (err, tokens) => {
if (err) {
console.error('JWT authorization error:', err);
return;
}
const calendar = google.calendar({ version: 'v3', auth: jwtClient });
const event = {
summary: 'Konsultasi: ' + $json.topic + ' - ' + $json.client_name,
start: {
dateTime: new Date($json.date + 'T' + $json.start_time).toISOString(),
timeZone: 'Asia/Jakarta',
},
end: {
dateTime: new Date($json.date + 'T' + $json.end_time).toISOString(),
timeZone: 'Asia/Jakarta',
},
description: 'Client: ' + $json.client_email + '\n\n' + $json.notes,
attendees: [
{ email: $json.client_email },
],
conferenceData: {
createRequest: {
requestId: $json.slot_id,
conferenceSolutionKey: { type: 'hangoutsMeet' },
},
},
};
try {
const result = await calendar.events.insert({
calendarId: $json.calendar_id,
resource: event,
conferenceDataVersion: 1,
});
return {
meet_link: result.data.hangoutLink,
event_id: result.data.id,
};
} catch (error) {
console.error('Error creating calendar event:', error);
throw error;
}
});
Incoming Webhook Payload
Your n8n webhook at /webhook-test/create-meet will receive:
{
"slot_id": "uuid-of-slot",
"date": "2025-12-25",
"start_time": "14:00:00",
"end_time": "15:00:00",
"client_name": "John Doe",
"client_email": "john@example.com",
"topic": "Business Consulting",
"notes": "Discuss project roadmap",
"calendar_id": "your-calendar@gmail.com",
"brand_name": "Your Brand",
"test_mode": true
}
Expected Response
Your n8n workflow should return:
{
"meet_link": "https://meet.google.com/abc-defg-hij",
"event_id": "event-id-from-google-calendar"
}
Security Notes
- Never commit the service account JSON to version control
- Store it securely in n8n credentials
- Rotate the key if compromised
- Only grant minimum necessary permissions to the service account
Troubleshooting
Error: 403 Forbidden
- Check if the calendar is shared with the service account email
- Verify the service account has Editor permissions
Error: 401 Unauthorized
- Verify the service account JSON is correct
- Check if Calendar API is enabled in Google Cloud Console
Error: 400 Invalid
- Check date/time format (should be ISO 8601)
- Verify calendar ID is correct
- Ensure the service account email format is correct
Alternative: Use Google Calendar API Key (Less Secure)
If you don't want to use service accounts, you can create an API key:
- Go to Google Cloud Console → APIs & Services → Credentials
- Click Create Credentials → API Key
- Restrict the key to Google Calendar API only
- Use it with HTTP requests
However, this is not recommended for production as it's less secure than service accounts.