Zone Settings, Cloudflare API

· ·

Recently I was trying to figure out how to use Cloudflare’s API to update the minimum TLS version across many domains in a Cloudflare account quickly. The request curl sample provided by Cloudflare for Edit zone setting didn’t include a data option (-d / –data), so I wasn’t sure how to package the values required in the PATCH request.

# Cloudflare request sample: Shell / cURL
curl --request PATCH \
  --url https://api.cloudflare.com/client/v4/zones/zone_id/settings/setting_id \
  --header 'Authorization: Bearer undefined' \
  --header 'Content-Type: application/json'

Initially I thought the data payload might have needed to be a dictionary with the actual name of the zone setting as the key, e.g. { ‘zone_setting’: ‘value’ }, but this resulted in the following error:

curl --request PATCH \
  --url https://api.cloudflare.com/client/v4/zones/$zone_id/settings/min_tls_version \
  --header "Authorization: Bearer $token" \  
  --header 'Content-Type: application/json' \
  --data '{ "min_tls_version": "1.2" }'

{"success":false,"errors":[{"code":1007,"message":"Invalid value for zone setting min_tls_version"}],"messages":[],"result":null}%

The answer was more obvious.

The dictionary should have used the keys referenced by Cloudflare in the image above, e.g. '{"id": "min_tls_version", "value": "1.2"}'