Modify document metadata (but not its contents)
One script reply has been approved by the moderators Verified
Created by hugo697 329 days ago
Submitted by hugo697 Bun
Verified 329 days ago
1
//native
2
type Grist = {
3
  apiKey: string;
4
  host: string;
5
};
6
/**
7
 * Modify document metadata (but not its contents)
8
 *
9
 */
10
export async function main(
11
  auth: Grist,
12
  docId: string,
13
  body: { name?: string; isPinned?: false | true },
14
) {
15
  const url = new URL(`https://${auth.host}/api/docs/${docId}`);
16

17
  const response = await fetch(url, {
18
    method: "PATCH",
19
    headers: {
20
      "Content-Type": "application/json",
21
      Authorization: "Bearer " + auth.apiKey,
22
    },
23
    body: JSON.stringify(body),
24
  });
25
  if (!response.ok) {
26
    const text = await response.text();
27
    throw new Error(`${response.status} ${text}`);
28
  }
29
  return await response.text();
30
}
31