Reputation: 53
I have seen loads of examples where it is shown how to delete a row or a sheet inside a google spreadsheet, but i am trying to delete the spreadsheet itself and am stuck at the syntax. the below code does not do anything. Can someone please help out?
deleteSheet = async () => {
const request = await fetch(
`https://sheets.googleapis.com/v4/spreadsheets`,
{
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${ACCESS_TOKEN}`,
spreadsheetId: `Bearer ${SpreadsheetId}`,
},
}
);
const data = await request.json();
console.log(data);
return data;
};
Upvotes: 1
Views: 224
Reputation: 201533
I believe your goal as follows.
For this, how about this answer?
In order to delete Google Spreadsheet, please use the Files: delete method in Drive API. Unfortunately, the Google Spreadsheet cannot be deleted using Sheets API.
const request = await fetch(
`https://sheets.googleapis.com/v4/spreadsheets`,
{
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${ACCESS_TOKEN}`,
spreadsheetId: `Bearer ${SpreadsheetId}`,
},
}
);
const request = await fetch(
`https://www.googleapis.com/drive/v3/files/${SpreadsheetId}`,
{
method: 'DELETE',
headers: {
Authorization: `Bearer ${ACCESS_TOKEN}`,
},
}
);
Upvotes: 1