0
get variable
One script reply has been approved by the moderators Verified
Created by admin 198 days ago Viewed 102 times
0
Submitted by admin Typescript (fetch-only)
Verified 198 days ago
1
/**
2
 * get variable
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  path: string,
8
  decrypt_secret: string | undefined
9
) {
10
  const url = new URL(`${BASE_URL}/api/w/${workspace}/variables/get/${path}`);
11
  for (const [k, v] of [["decrypt_secret", decrypt_secret]]) {
12
    if (v !== undefined && v !== "") {
13
      url.searchParams.append(k, v);
14
    }
15
  }
16
  const response = await fetch(url, {
17
    method: "GET",
18
    headers: {
19
      Authorization: "Bearer " + WM_TOKEN,
20
    },
21
    body: undefined,
22
  });
23
  if (!response.ok) {
24
    const text = await response.text();
25
    throw new Error(`${response.status} ${text}`);
26
  }
27
  return await response.json();
28
}
29