Delete list items

Removes one or more items from a list. This operation is asynchronous. To get current the operation status, invoke the [Get bulk operation status](#lists-get-bulk-operation-status) endpoint with the returned `operation_id`.

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
 * Delete list items
8
 * Removes one or more items from a list.
9

10
This operation is asynchronous. To get current the operation status, invoke the [Get bulk operation status](#lists-get-bulk-operation-status) endpoint with the returned `operation_id`.
11
 */
12
export async function main(
13
  auth: Cloudflare,
14
  list_id: string,
15
  account_identifier: string,
16
  body: {
17
    items?: { id?: string; [k: string]: unknown }[];
18
    [k: string]: unknown;
19
  }
20
) {
21
  const url = new URL(
22
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/rules/lists/${list_id}/items`
23
  );
24

25
  const response = await fetch(url, {
26
    method: "DELETE",
27
    headers: {
28
      "X-AUTH-EMAIL": auth.email,
29
      "X-AUTH-KEY": auth.key,
30
      "Content-Type": "application/json",
31
      Authorization: "Bearer " + auth.token,
32
    },
33
    body: JSON.stringify(body),
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41