I am developing an Add-on that aims to keep the sales on a marketplace in synced with Google Sheets. There is a first time sync that writes the last year orders into the sheet and that happens from within the add on execution, all good there.
Now I receive notifications in a cloud function when there is a new sale, and I want to add that information to the spreadsheet that the Add-on has been given permission to, but I don't know how to authenticate the request. I have tried with an editor service account and also creating a key for the main app engine account and nothing works.
Everything is part of the same google project, and the users will be anyone that install the add on and gives access to it, some help or direction will be highly appreciated.
Scopes the add on has permissions:
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/spreadsheets.currentonly",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/script.locale",
"https://www.googleapis.com/auth/script.scriptapp",
"https://www.googleapis.com/auth/script.container.ui"
Example usage:
import { google } from 'googleapis';
import serviceAccount from '../service-account.json';
const sheets = google.sheets('v4');
const jwtClient = new google.auth.JWT({
email: serviceAccount.client_email,
key: serviceAccount.private_key,
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
});
async function searchMetadata(spreadsheetId, params = {}) {
await jwtClient.authorize();
const response = await sheets.spreadsheets.developerMetadata.search({
auth: jwtClient,
spreadsheetId,
requestBody: {
dataFilters: [
{
developerMetadataLookup: params
}
]
}
})
return response.data;
}
Thanks!