Purge cache with API token unsupported?

I’m trying to purge a specific file by URL (relevant documentation)

This works (API Key):
curl -X POST "https://api.cloudflare.com/client/v4/zones/[zone id]/purge_cache" -H "X-Auth-Email: [email protected]" -H "X-Auth-Key: "aaaabbbbcccc111122223333" --data '{"files": ["test.example.com/pathtofile.css"]}'

This returns a 10000 Authentication error (API Token):
curl -X POST "https://api.cloudflare.com/client/v4/zones/[zone id]/purge_cache" -H "Authorization: bearer aaaabbbbcccc111122223333" --data '{"files": ["test.example.com/pathtofile.css"]}'

I believe this part of the API docs says that I should be able to use API tokens or API keys with the v4 API. Are API tokens just unofficially not supported with /zones/[zone id]/purge_cache?

Works just fine with API tokens.

Assuming the zone ID is correct in both cases, it will be most likely an issue with missing permissions on a token level. Make sure the token has the right permissions.

@sandro I forgot to mention, I believe I did that. The token has Zone:Edit and Cache Purge:Purge for all zones, which seems to satisfy the requirements which say permission needed: #cache_purge:edit

I just checked it and did not even need “zone edit”, “cache purge” was enough.

image

Double check the zone ID and maybe create the token from scratch. If nothing else works and you double checked everything you might want to open a support ticket.

In general, however, tokens should work fine for the cache purge. As I said I just tested it a couple of minutes ago and the call went through.

Possibly write “Bearer” instead of “bearer”.

@sandro wow. That was the problem. It works with a lowercase ‘b’ with everything else that I tried, including the API key version of the same purge_cache request. Thank you for the help!