create draft

Script windmill Verified

by admin ยท 8/13/2023

The script

Submitted by admin Typescript (fetch-only)
Verified 370 days ago
1
/**
2
 * create draft
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  body: {
8
    path: string;
9
    typ: "flow" | "script" | "app";
10
    value?: unknown;
11
    [k: string]: unknown;
12
  }
13
) {
14
  const url = new URL(`${BASE_URL}/api/w/${workspace}/drafts/create`);
15

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