ww7
July 4, 2023, 3:36am
1
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
simon
July 4, 2023, 12:42pm
4
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?
ww7
July 4, 2023, 1:03pm
5
Sorry, header I missed in the post, but with it the same problem…
ww7
July 4, 2023, 1:05pm
6
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": []
}
ww7
July 4, 2023, 1:30pm
7
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": []
}
ww7
July 4, 2023, 1:37pm
8
Found another 3 forum treads with same error without solution.
Documentation and feature incomplete and seems not works.
simon
July 4, 2023, 2:32pm
9
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
ww7
July 4, 2023, 4:02pm
11
A bit unclear because this is not shown in examples.
2 Likes
simon
July 4, 2023, 4:53pm
12
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
system
Closed
July 7, 2023, 4:54pm
13
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.