Skip to content

Add Lists endpoint for account rule lists - #285

Open
sheyDev wants to merge 1 commit into
cloudflare:masterfrom
sheyDev:add-lists-endpoint
Open

sheyDev wants to merge 1 commit into
cloudflare:masterfrom
sheyDev:add-lists-endpoint

Conversation

@sheyDev

@sheyDev sheyDev commented Nov 27, 2026

Copy link
Copy Markdown

Adds a Lists endpoint for account-level lists (IP, hostname, ASN and redirect) that rule expressions use, e.g. ip.src in $my_list. The SDK had no way to manage these, so you had to call the adapter directly.

Changes

New Cloudflare\API\Endpoints\Lists class, following the pattern of the other endpoints (getBody() returns the last response):

Method Request
listLists($accountId) GET accounts/{account_id}/rules/lists
getListDetails($accountId, $listId) GET accounts/{account_id}/rules/lists/{list_id}
createList($accountId, $kind, $name, $description = '') POST accounts/{account_id}/rules/lists
updateListDescription($accountId, $listId, $description) PUT accounts/{account_id}/rules/lists/{list_id}
deleteList($accountId, $listId) DELETE accounts/{account_id}/rules/lists/{list_id}
listListItems($accountId, $listId, $search = '', $perPage = 0, $cursor = '') GET accounts/{account_id}/rules/lists/{list_id}/items
getListItem($accountId, $listId, $itemId) GET accounts/{account_id}/rules/lists/{list_id}/items/{item_id}
createListItems($accountId, $listId, $items) POST accounts/{account_id}/rules/lists/{list_id}/items
replaceListItems($accountId, $listId, $items) PUT accounts/{account_id}/rules/lists/{list_id}/items
deleteListItems($accountId, $listId, $itemIds) DELETE accounts/{account_id}/rules/lists/{list_id}/items
getBulkOperation($accountId, $operationId) GET accounts/{account_id}/rules/lists/bulk_operations/{operation_id}

Notes on behaviour:

  • Adding, replacing and deleting items is asynchronous in the API. These three methods return the operation ID, and getBulkOperation() returns its status (pending, running, completed, or failed with an error message).
  • $items is passed as is, so it works for any list kind, e.g. [['ip' => '192.0.2.1', 'comment' => 'optional']].
  • listListItems() returns result and result_info. To get the next page, pass result_info->cursors->after as $cursor.
  • Optional query and body fields are only sent when set, the same as in AccessRules.

Also updated the README feature list and added an Unreleased entry to the changelog.

Example

$lists = new Cloudflare\API\Endpoints\Lists($adapter);

$list = $lists->createList($accountId, 'ip', 'blocked_ips', 'Addresses to block');
$operationId = $lists->replaceListItems($accountId, $list->id, [
    ['ip' => '192.0.2.1'],
    ['ip' => '198.51.100.0/24', 'comment' => 'Abusive range'],
]);

$operation = $lists->getBulkOperation($accountId, $operationId);

Testing

  • Added tests/Endpoints/ListsTest.php (13 tests) with JSON fixtures taken from the API reference.
  • make fix changed nothing, and phpmd reports nothing for the new files.
  • make test: everything passes except 5 tests in GuzzleTest, which call httpbin.org and fail on master as well. They don't touch the code in this PR.

API reference: https://developers.cloudflare.com/api/resources/rules/subresources/lists/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant