Patch Pools

Apply changes to a number of existing pools, overwriting the supplied properties. Pools are ordered by ascending `name`. Returns the list of affected pools. Supports the standard pagination query parameters, either `limit`/`offset` or `per_page`/`page`.

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Patch Pools
8
 * Apply changes to a number of existing pools, overwriting the supplied properties. Pools are ordered by ascending `name`. Returns the list of affected pools. Supports the standard pagination query parameters, either `limit`/`offset` or `per_page`/`page`.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  body: { notification_email?: '""'; [k: string]: unknown }
13
) {
14
  const url = new URL(
15
    `https://api.cloudflare.com/client/v4/user/load_balancers/pools`
16
  );
17

18
  const response = await fetch(url, {
19
    method: "PATCH",
20
    headers: {
21
      "X-AUTH-EMAIL": auth.email,
22
      "X-AUTH-KEY": auth.key,
23
      "Content-Type": "application/json",
24
      Authorization: "Bearer " + auth.token,
25
    },
26
    body: JSON.stringify(body),
27
  });
28
  if (!response.ok) {
29
    const text = await response.text();
30
    throw new Error(`${response.status} ${text}`);
31
  }
32
  return await response.json();
33
}
34