Create an empty 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
 * Create an empty document
8
 *
9
 */
10
export async function main(
11
  auth: Grist,
12
  workspaceId: string,
13
  body: { name?: string; isPinned?: false | true },
14
) {
15
  const url = new URL(
16
    `https://${auth.host}/api/workspaces/${workspaceId}/docs`,
17
  );
18

19
  const response = await fetch(url, {
20
    method: "POST",
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.json();
32
}
33