get resource interpolated (variables and resources are fully unrolled)

Script windmill Verified

by admin ยท 10/22/2023

The script

Submitted by admin Typescript (fetch-only)
Verified 370 days ago
1
/**
2
 * get resource interpolated (variables and resources are fully unrolled)
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  path: string,
8
  job_id: string | undefined
9
) {
10
  const url = new URL(
11
    `${BASE_URL}/api/w/${workspace}/resources/get_value_interpolated/${path}`
12
  );
13
  for (const [k, v] of [["job_id", job_id]]) {
14
    if (v !== undefined && v !== "") {
15
      url.searchParams.append(k, v);
16
    }
17
  }
18
  const response = await fetch(url, {
19
    method: "GET",
20
    headers: {
21
      Authorization: "Bearer " + WM_TOKEN,
22
    },
23
    body: undefined,
24
  });
25
  if (!response.ok) {
26
    const text = await response.text();
27
    throw new Error(`${response.status} ${text}`);
28
  }
29
  return await response.json();
30
}
31