I am using google APIs to create an event and add a google meet link to that event.
Calendar event creation is working fine but I am not able to add a google meet link
const response = await calendar.events.patch({
auth: auth,
calendarId: calendarId,
eventId: "6df3sea0jhl6tueoos4qjr41a0",
requestBody: {
conferenceData: {
createRequest: {
requestId: "asdafas14",
},
conferenceSolution: {
key: {
type: "hangoutsMeet",
},
},
},
},
sendNotifications: true,
conferenceDataVersion: 1,
});
With the above payload, the response is 200 but no meeting link was added
Also tried this by changing payload
await calendar.events.patch({
auth: auth,
calendarId: calendarId,
eventId: "6df3sea0jhl6tueoos4qjr41a0",
requestBody: {
conferenceData: {
createRequest: {
requestId: "asdafas14",
conferenceSolutionKey: {
type: "hangoutsMeet",
},
},
},
},
sendNotifications: true,
conferenceDataVersion: 1,
});
Response is 400 and gives the errors
{
domain: 'global',
reason: 'invalid',
message: 'Invalid conference type value.'
}
I am using a developer service account from https://console.cloud.google.com/apis/dashboard
Can anyone please help me with what is wrong here? Thanks in advance
I made it work with a few changes to your code, the the following example:
const response = await calendar.events.patch({
auth: auth,
calendarId: calendarId,
// I replace my event ID for yours
// so you can only copy and paste it on your code.
eventId: "6df3sea0jhl6tueoos4qjr41a0",
requestBody: {
"conferenceData": {
"createRequest": {
// place "conferenceSolutionKey" inside "createRequest"
"conferenceSolutionKey": {
"type": "hangoutsMeet"
},
// change the request of the requestID
"requestId": "sample1234"
},
},
},
sendNotifications: true,
conferenceDataVersion: 1,
});
console.log(response.data.hangoutLink);
Reference:
](https://developers.google.com/calendar/api/quickstart/js)
const fs = require('fs').promises;
const path = require('path');
const process = require('process');
const { authenticate } = require('@google-cloud/local-auth');
const { google } = require('googleapis');
// If modifying these scopes, delete token.json.
const SCOPES = ['https://www.googleapis.com/auth/calendar'];
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
const TOKEN_PATH = path.join(process.cwd(), 'token.json');
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');
/**
* Reads previously authorized credentials from the save file.
*
* @return {Promise<OAuth2Client|null>}
*/
async function loadSavedCredentialsIfExist() {
try {
const content = await fs.readFile(TOKEN_PATH);
const credentials = JSON.parse(content);
return google.auth.fromJSON(credentials);
} catch (err) {
return null;
}
}
/**
* Serializes credentials to a file compatible with GoogleAUth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
*/
async function saveCredentials(client) {
const content = await fs.readFile(CREDENTIALS_PATH);
const keys = JSON.parse(content);
const key = keys.installed || keys.web;
const payload = JSON.stringify({
type: 'authorized_user',
client_id: key.client_id,
client_secret: key.client_secret,
refresh_token: client.credentials.refresh_token,
});
await fs.writeFile(TOKEN_PATH, payload);
}
/**
* Load or request or authorization to call APIs.
*
*/
async function authorize() {
let client = await loadSavedCredentialsIfExist();
if (client) {
return client;
}
client = await authenticate({
scopes: SCOPES,
keyfilePath: CREDENTIALS_PATH,
});
if (client.credentials) {
await saveCredentials(client);
}
return client;
}
/**
* Makes the patch request to add the a meet link.
*
*/
const response = await calendar.events.patch({
calendarId: 'primary',
eventId: "eventId",
requestBody: {
"conferenceData": {
"createRequest": {
"conferenceSolutionKey": {
"type": "hangoutsMeet"
}, "requestId": "sample1234"
},
},
},
sendNotifications: true,
conferenceDataVersion: 1,
});
console.log(response.data.hangoutLink);
}
authorize().then(listEvents).catch(console.error);