Get bulk operation status

Gets the current status of an asynchronous operation on a list. The `status` property can have one of the following values: `pending`, `running`, `completed`, or `failed`. If the status is `failed`, the `error` property will contain a message describing the error.

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
 * Get bulk operation status
8
 * Gets the current status of an asynchronous operation on a list.
9

10
The `status` property can have one of the following values: `pending`, `running`, `completed`, or `failed`. If the status is `failed`, the `error` property will contain a message describing the error.
11
 */
12
export async function main(
13
  auth: Cloudflare,
14
  operation_id: string,
15
  account_identifier: string
16
) {
17
  const url = new URL(
18
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/rules/lists/bulk_operations/${operation_id}`
19
  );
20

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