Reputation: 13
I want to insert an event using axios post request. This is the code:
async function inserisciTurni() {
axios.post(`https://www.googleapis.com/calendar/v3/calendars/${calendarioselezionato}/events`, {
calendarId: `${calendarioselezionato}`,
resource: evento,
headers: {
authorization: `Bearer ${accessToken}`,
},
}).then((result) => { console.log(result) })
var evento = {
"summary": "Titolo prova evento",
"description": "prova evento",
"start": {
"dateTime": "2022-08-28T09:00:00-07:00",
},
"end": {
"dateTime": "2022-08-28T17:00:00-07:00",
} };
But I receive this error:
Upvotes: 0
Views: 1125
Reputation: 201493
I thought that in your script, your request body is correct. But, I thought that it is required to modify the method for requesting. So, in your script, how about the following modification?
async function inserisciTurni() {
var accessToken = "###"; // Please set your access token.
var calendarioselezionato = "###"; // Please set your calendar ID.
var evento = {
"summary": "Titolo prova evento",
"description": "prova evento",
"start": {
"dateTime": "2022-08-28T09:00:00-07:00",
},
"end": {
"dateTime": "2022-08-28T17:00:00-07:00",
}
};
var res = await axios.post(
`https://www.googleapis.com/calendar/v3/calendars/${calendarioselezionato}/events`,
JSON.stringify(evento),
{headers: {authorization: `Bearer ${accessToken}`, "Content-Type": "application/json"}}
);
console.log(res.data);
}
Upvotes: 1