1 | |
2 | type Grist = { |
3 | apiKey: string; |
4 | host: string; |
5 | }; |
6 | |
7 | * Delete rows of a table |
8 | * |
9 | */ |
10 | export async function main( |
11 | auth: Grist, |
12 | docId: string, |
13 | tableId: string, |
14 | body: number[], |
15 | ) { |
16 | const url = new URL( |
17 | `https://${auth.host}/api/docs/${docId}/tables/${tableId}/data/delete`, |
18 | ); |
19 |
|
20 | const response = await fetch(url, { |
21 | method: "POST", |
22 | headers: { |
23 | "Content-Type": "application/json", |
24 | Authorization: "Bearer " + auth.apiKey, |
25 | }, |
26 | body: JSON.stringify(body), |
27 | }); |
28 | if (!response.ok) { |
29 | const text = await response.text(); |
30 | throw new Error(`${response.status} ${text}`); |
31 | } |
32 | return await response.text(); |
33 | } |
34 |
|