Change who has access to document
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
 * Change who has access to document
8
 *
9
 */
10
export async function main(
11
  auth: Grist,
12
  docId: string,
13
  body: {
14
    delta: { maxInheritedRole?: "owners" | "editors" | "viewers"; users?: {} };
15
  },
16
) {
17
  const url = new URL(`https://${auth.host}/api/docs/${docId}/access`);
18

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