Skip to content
Start here

Create list items

client.rules.lists.items.create(stringlistId, ItemCreateParams { account_id, body } params, RequestOptionsoptions?): ItemCreateResponse { operation_id }
POST/accounts/{account_id}/rules/lists/{list_id}/items

Appends new items to the list.

This operation is asynchronous. To get current the operation status, invoke the Get bulk operation status endpoint with the returned operation_id.

There is a limit of 1 pending bulk operation per account. If an outstanding bulk operation is in progress, the request will be rejected.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Account Filter Lists Edit
ParametersExpand Collapse
listId: string

The unique ID of the list.

maxLength32
minLength32
params: ItemCreateParams { account_id, body }
account_id: string

Path param: The Account ID for this resource.

maxLength32
minLength32
body: Array<ListsListItemIPComment { ip, comment } | ListsListItemRedirectComment { redirect, comment } | ListsListItemHostnameComment { hostname, comment } | ListsListItemASNComment { asn, comment } >

Body param

One of the following:
ListsListItemIPComment { ip, comment }
ip: string

An IPv4 address, an IPv4 CIDR, an IPv6 address, or an IPv6 CIDR.

comment?: string

Defines an informative summary of the list item.

ListsListItemRedirectComment { redirect, comment }
redirect: Redirect { source_url, target_url, include_subdomains, 4 more }

The definition of the redirect.

source_url: string
target_url: string
include_subdomains?: boolean
preserve_path_suffix?: boolean
preserve_query_string?: boolean
status_code?: 301 | 302 | 307 | 308
One of the following:
301
302
307
308
subpath_matching?: boolean
comment?: string

Defines an informative summary of the list item.

ListsListItemHostnameComment { hostname, comment }
hostname: Hostname { url_hostname, exclude_exact_hostname }

Valid characters for hostnames are ASCII(7) letters from a to z, the digits from 0 to 9, wildcards (*), and the hyphen (-).

url_hostname: string
exclude_exact_hostname?: boolean

Only applies to wildcard hostnames (e.g., *.example.com). When true (default), only subdomains are blocked. When false, both the root domain and subdomains are blocked.

comment?: string

Defines an informative summary of the list item.

ListsListItemASNComment { asn, comment }
asn: number

Defines a non-negative 32 bit integer.

comment?: string

Defines an informative summary of the list item.

ReturnsExpand Collapse
ItemCreateResponse { operation_id }
operation_id: string

The unique operation ID of the asynchronous action.

Create list items

import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});

const item = await client.rules.lists.items.create('2c0fc9fa937b11eaa1b71c4d701ab86e', {
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  body: [{ ip: '10.0.0.1' }],
});

console.log(item.operation_id);
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "operation_id": "4da8780eeb215e6cb7f48dd981c4ea02"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "operation_id": "4da8780eeb215e6cb7f48dd981c4ea02"
  },
  "success": true
}