Configuration API

Cloudflare’s API allows you to upload and activate Workers without using our UI. You can use the API to integrate Cloudflare Workers into your CLI, build process, or tooling. If you are on the Enterprise Plan, please check out the this page for the configuration API.

The Basics

Each request you make will need the following:

Your Cloudflare Email

This will be the email address you used to signup with Cloudflare. We will refer to this as YOUR_CLOUDFLARE_EMAIL in the examples below.

Account Authentication Key

You can find your Account Authentication Key by visiting https://www.cloudflare.com/a/profile. We will refer to this as ACCOUNT_AUTH_KEY in the examples below. Account Authentication Key

Zone ID

You can find your Zone ID by visiting https://www.cloudflare.com/a/overview/YOUR_DOMAIN Zone ID

Endpoints

Upload a Worker

PUT /zones/:zone_id/workers/script

Upload a Worker (or new version of a Worker).

curl -X PUT "https://api.cloudflare.com/client/v4/zones/:zone_id/workers/script" -H
"X-Auth-Email:YOUR_CLOUDFLARE_EMAIL" -H "X-Auth-Key:ACCOUNT_AUTH_KEY" -H
"Content-Type:application/javascript" --data-binary "@PATH_TO_YOUR_WORKER_SCRIPT"

Download a Worker

GET /zones/:zone_id/workers/script

Download the latest version of the Worker. The response body is raw Javascript (not JSON).

curl -X GET "https://api.cloudflare.com/client/v4/zones/:zone_id/workers/script" -H
"X-Auth-Email:YOUR_CLOUDFLARE_EMAIL" -H "X-Auth-Key:ACCOUNT_AUTH_KEY"

Delete a Worker

DELETE /zones/:zone_id/workers/script

Delete a Worker.

curl -X DELETE "https://api.cloudflare.com/client/v4/zones/:zone_id/workers/script" -H
"X-Auth-Email:YOUR_CLOUDFLARE_EMAIL" -H "X-Auth-Key:ACCOUNT_AUTH_KEY"

Create a Route

POST /zones/:zone_id/workers/filters

Create a route for your Worker. Note that by setting enabled to true, your Worker will run on the provided pattern. If you want to create a route where the Worker will not run, set enabled to false.

curl -X POST "https://api.cloudflare.com/client/v4/zones/:zone_id/workers/filters" -H
"X-Auth-Email:YOUR_CLOUDFLARE_EMAIL" -H "X-Auth-Key:ACCOUNT_AUTH_KEY" -H "Content-type: application/json" -d '{"pattern": "example.com/*", "enabled": true}'

The response body will be JSON encoded and look similar to:

{
    "result": {
        "id": "000000000000000000000"
    }
}

You can use the returned filter ID to enable, disable, update the pattern, or delete a route.

Change an Existing Route

PUT /zones/:zone_id/workers/filters/:filter_id

Change an existing route. You can change the pattern as well as the enabled state of an existing route. Note that patterns must be unique, and attempting to change (or create) a route with a pattern that already exists will return a 409 Conflict.

curl -X PUT "https://api.cloudflare.com/client/v4/zones/:zone_id/workers/filters/:filter_id" -H
"X-Auth-Email:YOUR_CLOUDFLARE_EMAIL" -H "X-Auth-Key:ACCOUNT_AUTH_KEY" -H "Content-type: application/json" -d '{"pattern": "example.com/*", "enabled": false}'

Get Assigned Routes

GET /zones/:zone_id/workers/filters

Get the list of routes. This is an enveloped JSON list of objects.

curl -X GET "https://api.cloudflare.com/client/v4/zones/:zone_id/workers/filters" -H
"X-Auth-Email:YOUR_CLOUDFLARE_EMAIL" -H "X-Auth-Key:ACCOUNT_AUTH_KEY"

Delete a Route

DELETE /zones/:zone_id/workers/filters/:filter_id

Delete a route. You can retrieve the filter_id from getting the assigned routes.

curl -X DELETE "https://api.cloudflare.com/client/v4/zones/:zone_id/workers/filters/:filter_id" -H
"X-Auth-Email:YOUR_CLOUDFLARE_EMAIL" -H "X-Auth-Key:ACCOUNT_AUTH_KEY"