Delete list items example, please

I can’t find correct syntax of API
https://developers.cloudflare.com/api/operations/lists-delete-list-items

Seems deleting simply not work on API level or documentation is not complete

GET of item details works

curl --request GET \
  --url https://api.cloudflare.com/client/v4/accounts/$account_identifier/rules/lists/$list_id/items/4cc8c8b79cfa41f9a60290e8a392375f \
  --header 'Content-Type: application/json' \
  --header "Authorization: Bearer $token"
{
  "result": {
    "id": "4cc8c8b79cfa41f9a60290e8a392375f",
    "ip": "91.211.135.179",
    "created_on": "2023-07-04T00:50:33Z",
    "modified_on": "2023-07-04T00:50:33Z"
  },
  "success": true,
  "errors": [],
  "messages": []
}

but DELETE not,

curl --request DELETE \
  --url https://api.cloudflare.com/client/v4/accounts/$account_identifier/rules/lists/$list_id/items \
  --header "Authorization: Bearer $token" \
  --data '[{"id":"4Cc8c8b79cfa41f9a60290e8a392375f"}]'
{
  "result": null,
  "success": false,
  "errors": [
    {
      "code": 10026,
      "message": "filters.api.invalid_json"
    }
  ],
  "messages": []
}

Please help

On your DELETE request, you did not include the content type:

  --header 'Content-Type: application/json'

If you try that, does you get a different response?

Sorry, header I missed in the post, but with it the same problem…

curl --request DELETE \
  --url https://api.cloudflare.com/client/v4/accounts/$account_identifier/rules/lists/$list_id/items \
  --header 'Content-Type: application/json' \
  --header "Authorization: Bearer $token" \
  --data '[
  {"id": "4cc8c8b79cfa41f9a60290e8a392375f"}
]'
{
  "result": null,
  "success": false,
  "errors": [
    {
      "code": 10026,
      "message": "filters.api.invalid_json"
    }
  ],
  "messages": []
}

Interesting, also I can’t add IP via API

curl --request PUT   --url https://api.cloudflare.com/client/v4/accounts/$account_identifier/rules/lists/$list_id   --header 'Content-Type: application/json'   --header "Authorization: Bearer $toke
n"   --data '{
        "ip": "1.0.170.50",
        "comment": "test ip"
    }'
{
  "result": null,
  "success": false,
  "errors": [
    {
      "code": 10026,
      "message": "filters.api.invalid_json"
    }
  ],
  "messages": []
}

Found another 3 forum treads with same error without solution.
Documentation and feature incomplete and seems not works.

It’s quite unclear from the documentation, but you do need an items object at the top level of your JSON payload, like this:

{
	"items": [
	  {
		"id": "YOUR_ITEM_ID_HERE"
	  }
	]
}

That does match the structure of the payload in the docs, but it’s not really very easy to follow and we should have an explicit example of the payload in JSON format for you to work from. I’ll share this feedback internally, sorry for the confusion here.

EDIT: your call to add an item is slightly incorrect too, it should be an array of objects, e.g:

[
  {
    "comment": "test", 
    "ip":"1.2.3.4/32"
  }
]

From Cloudflare API Documentation

5 Likes

Thank you very much!

1 Like

A bit unclear because this is not shown in examples.

2 Likes

I agree - we have a plan to improve the Firewall API docs internally and I’ve raised a task relating to this specific report from you there also - so we should improve the docs in future with proper JSON payload examples.

4 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.