googleapis / googleapis/google-api-nodejs-client
Calendar: Invalid Value When Setting accessRole in requestBody of calendar.calendarList.insert
- Lingua principale
- TypeScript
- Stelle
- 12.2k
- Fork
- 2k
- Merge medio
- 1g 9h
- PR unite (30g)
- 24
Descrizione
I have a service account with domain-wide delegation enabled for Google Calendar. I'm trying to add a calendar to a user's calendar list within the domain while specifying a specific role for access.
**Issue**
When I include the `accessRole` property in the requestBody of the `calendar.calendarList.Insert` method, I receive an "Invalid Value" response error. Without specifying `accessRole`, the calendar gets added to the user's list with the default role of "reader."
In this [api reference of nodejs client library](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Calendarlist.html#insert)(), `accessRole` property is mentioned in requestBody. Moreover, intelligence in vscode also provides an option for `accessRole` in the `requestBody` of insert method.
#### Environment details
- OS: Ubuntu 22.04
- Node.js version: v18.14.0
- npm version: 9.3.1
- `googleapis` version: 118.0.0
#### Steps to reproduce
```javascript
import { google } from "googleapis";
import { JWT } from "google-auth-library";
const privateKey = process.env.GOOGLE_PRIVATE_KEY;
const googleClientEmail = process.env.GOOGLE_CLIENT_EMAIL;
const googlePrivateKey = privateKey.replace(/\\n/g, "\n");
const calendar = google.calendar("v3");
async function authorizeClient(email, serviceAccountEmail, privateKey, scopes) {
const jwtClient = new JWT(serviceAccountEmail, undefined, privateKey, scopes, email);
try {
await jwtClient.authorize();
return jwtClient;
} catch (error) {
throw new Error(`Failed to authorize client: ${error.message}`);
}
}
async function shareCalendar(calendarId, user) {
try {
const userJwtClient = await authorizeClient(user.email, googleClientEmail, googlePrivateKey, [
"https://www.googleapis.com/auth/calendar",
]);
const resp = await calendar.calendarList.insert({
auth: userJwtClient,
requestBody: {
id: calendarId,
accessRole: user.role,
},
});
console.log(resp.data);
} catch (error) {
console.log(error);
}
}
shareCalendar("c_dke9ue52o12rl6hjtdfjqnn044@group.calendar.google.com", {
email: "dev.test01@company.com",
role: "owner",
});
```
**expected Response**
calendar should be added to calendar list of "dev test01" user.
**Actual Response**
```
response: {
config: {
url: 'https://www.googleapis.com/calendar/v3/users/me/calendarList',
method: 'POST',
params: {},
validateStatus: [Function (anonymous)],
retry: true,
body: '{"id":"c_dke9ue52o12rl6hjtdfjqnn044@group.calendar.google.com","accessRole":"owner"}',
responseType: 'json', },
data: { error: [Object] },
status: 400,
statusText: 'Bad Request',
request: {
responseURL: 'https://www.googleapis.com/calendar/v3/users/me/calendarList'
}
},
code: 400,
errors: [ { domain: 'global', reason: 'invalid', message: 'Invalid Value' } ]
}
```
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Start with the calendar.calendarList.insert call and the linked Node.js API reference, then reproduce the request using the provided service-account and requestBody values. Compare the documented accessRole behavior with the 400 response and determine whether the client reference or the Calendar API usage is at fault; done means the behavior and any required correction are clearly documented.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, nodejs
- Ambito
- api
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100