1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
export let googleSheetBatchUpdate = async (
serviceAccount: string,
spreadsheetId: string,
batchUpdateData:
import("npm:googleapis").sheets_v4.Params$Resource$Spreadsheets$Batchupdate[
"requestBody"
]["requests"],
) => {
const { getToken } = await import(
"https://deno.land/x/google_jwt_sa@v0.2.3/mod.ts"
);
const token = await getToken(serviceAccount, {
scope: ["https://www.googleapis.com/auth/spreadsheets"],
});
const requestBody = {
requests: batchUpdateData,
};
const result = await fetchJSON(
`https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}:batchUpdate`,
{
method: "POST",
headers: {
Authorization: `Bearer ${token.access_token}`,
},
body: JSON.stringify(requestBody),
},
);
return result;
};
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.