By default, your HTTP request logs are not retained. When using the Logpull API for the first time, you will need to enable retention. You can also turn off retention at any time. Note that after retention is turned off, previously saved logs will be available until the retention period expires (refer to Data retention period ).
There are two endpoints for managing log retention:
GET /logs/control/retention/flag
- returns the current status of retention
POST /logs/control/retention/flag
- turns retention on or off
Note
In the Linux examples below we use the optional jq tool to help parse the response data.
To make a POST
call, you must have zone-scoped edit
permissions, such as Super Administrator, Administrator, or Log Share. Refer to Make API calls for more information.
Example API requests using cURL
Check log retention status
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag \
--header "Authorization: Bearer <API_TOKEN>"
curl.exe "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag" ^
--header "Authorization: Bearer <API_TOKEN>"
$ uri = "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag"
$ headers = @ { "Authorization" = "Bearer <API_TOKEN>" }
Invoke-RestMethod - Uri $ uri - Method Get - Headers $ headers
If the zone has log retention enabled you get the value true
, whereas a value of false
is returned when it is disabled .
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
curl.exe "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag" ^
--header "Authorization: Bearer <API_TOKEN>" ^
--header "Content-Type: application/json" ^
--data "{""flag"": true}"
$ uri = "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag"
$ headers = @ { "Authorization" = "Bearer <API_TOKEN>" }
$ bodyFlag = @ { flag = $ true } | ConvertTo-Json
Invoke-RestMethod - Uri $ uri - Method Post - Headers $ headers - Body $ bodyFlag - ContentType "application/json"
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
curl.exe "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag" ^
--header "Authorization: Bearer <API_TOKEN>" ^
--header "Content-Type: application/json" ^
--data "{""flag"": false}"
$ uri = "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag"
$ headers = @ { "Authorization" = "Bearer <API_TOKEN>" }
$ bodyFlag = @ { flag = $ false } | ConvertTo-Json
Invoke-RestMethod - Uri $ uri - Method Post - Headers $ headers - Body $ bodyFlag - ContentType "application/json"
Turning log retention on or off is recorded in Cloudflare Audit Logs .