create resource_type

Script windmill Verified

by admin ยท 8/13/2023

The script

Submitted by admin Typescript (fetch-only)
Verified 370 days ago
1
/**
2
 * create resource_type
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  body: {
8
    workspace_id?: string;
9
    name: string;
10
    schema?: unknown;
11
    description?: string;
12
    [k: string]: unknown;
13
  }
14
) {
15
  const url = new URL(`${BASE_URL}/api/w/${workspace}/resources/type/create`);
16

17
  const response = await fetch(url, {
18
    method: "POST",
19
    headers: {
20
      "Content-Type": "application/json",
21
      Authorization: "Bearer " + WM_TOKEN,
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