I’m having issues deleting an IP from my Cloudflare list using their API. My code seems to return a success message, but the IP stays on the list. Here’s what I’ve tried:
$accountInfo = '...'
$targetIP = '4514a...'
$requestBody = @{
entries = @(
@{ identifier = $targetIP }
)
}
$apiHeaders = @{
Auth = 'Bearer ...'
ContentType = 'application/json'
}
$response = Invoke-RestMethod -Method Remove `
-Uri "https://api.cloudflare.com/client/v4/accounts/$accountInfo/rules/lists/$listInfo/entries" `
-Headers $apiHeaders `
-Body ($requestBody | ConvertTo-Json -Depth 5)
The API returns success, but nothing changes on the website. Is there a way to remove IPs using their address (like 192.168.1.1) instead of an ID? Any help would be great!
In my experience dealing with Cloudflare’s API, it can help to verify that the correct list identifier is being used. Sometimes the selected list does not match the one intended, making it appear as if the removal failed. Additionally, check that the IP address is formatted exactly as expected by Cloudflare, as even minor differences could lead to issues. Consider switching the HTTP method from Remove to DELETE since this may be required by the API. It is also important to ensure that your API token has the necessary administrative permissions. Finally, be aware that there might be a short delay before changes are reflected on the dashboard.
hey there, i’ve run into similar issues before. have u tried using the DELETE method instead of Remove? also, double-check ur API token permissions. sometimes cloudflare’s dashboard takes a bit to update after changes. if none of that works, maybe try removing by IP directly instead of identifier?
I’ve dealt with this exact issue before, and it can be frustrating. One thing that worked for me was using the ‘ip’ parameter instead of ‘identifier’ in the request body. Try modifying your code like this:
$requestBody = @{
ip = $targetIP
}
Also, make sure you’re using the correct list ID. Sometimes Cloudflare creates multiple lists, and you might be targeting the wrong one. Double-check this in your account settings.
If that doesn’t work, try clearing your browser cache or waiting a bit. Sometimes the changes take a while to propagate through Cloudflare’s system, even though the API returns a success message. Hope this helps!
make sure you’re using the DELETE method and passing the IP value directly, not the identifier. check token permissions too. i’ve used default router IP addresses when troubleshooting network access, but for Cloudflare lists the format must match exactly what they store
Cloudflare’s API does not support deleting list items directly by IP address. The DELETE endpoint requires the item ID that Cloudflare assigns when an entry is added to the list.
To remove an IP like 192.168.1.1:
-
Look up the item ID with a GET request:
-
GET https://api.cloudflare.com/client/v4/accounts/{account_id}/rules/lists/{list_id}/items
-
Locate the entry with matching IP and copy its id.
-
Send the DELETE request using the item ID in the JSON body:
-
DELETE https://api.cloudflare.com/client/v4/accounts/{account_id}/rules/lists/{list_id}/items
-
Headers:
-
- Authorization: Bearer <API_TOKEN>
-
- Content-Type: application/json
- Payload:
- {
- “items”: [
-
{
-
"id": "<item_id>"
-
}
- ]
- }
-
The operation requires the DELETE method and an array of objects specifying each item ID under the items key.
The URL in the example is also using /entries; Cloudflare’s list-item removal endpoint is /items. First GET the items, match the IP, then DELETE using that item’s id in an items array. In PowerShell, use -Method Delete and send Authorization and Content-Type headers; a successful response to the wrong endpoint or payload won’t remove the entry.