Skip to content
Start here

Put script content

PUT/accounts/{account_id}/workers/scripts/{script_name}/content

Put script content without touching config or metadata.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Workers Scripts Write
Path ParametersExpand Collapse
account_id: string

Identifier.

maxLength32
script_name: string

Name of the script, used in URLs and route configuration.

Header ParametersExpand Collapse
"CF-WORKER-BODY-PART": optional string
"CF-WORKER-MAIN-MODULE-PART": optional string
Body ParametersForm DataExpand Collapse
metadata: { body_part, main_module }

JSON-encoded metadata about the uploaded parts and Worker configuration.

body_part: optional string

Name of the uploaded file that contains the Worker script (e.g. the file adding a listener to the fetch event). Indicates a service worker syntax Worker.

main_module: optional string

Name of the uploaded file that contains the main module (e.g. the file exporting a fetch handler). Indicates a module syntax Worker.

files: optional array of string

An array of modules (often JavaScript files) comprising a Worker script. At least one module must be present and referenced in the metadata as main_module or body_part by filename.
Possible Content-Type(s) are: application/javascript+module, text/javascript+module, application/javascript, text/javascript, text/x-python, text/x-python-requirement, application/wasm, text/plain, application/octet-stream, application/source-map.

ReturnsExpand Collapse
errors: array of { code, message, documentation_url, source }
code: number
minimum1000
message: string
documentation_url: optional string
source: optional { pointer }
pointer: optional string
messages: array of { code, message, documentation_url, source }
code: number
minimum1000
message: string
documentation_url: optional string
source: optional { pointer }
pointer: optional string
result: Script { id, compatibility_date, compatibility_flags, 18 more }
id: optional string

The name used to identify the script.

compatibility_date: optional string

Date indicating targeted support in the Workers runtime. Backwards incompatible fixes to the runtime following this date will not affect this Worker.

compatibility_flags: optional array of string

Flags that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a compatibility_date.

created_on: optional string

When the script was created.

formatdate-time
etag: optional string

Hashed script content, can be used in a If-None-Match header when updating.

handlers: optional array of string

The names of handlers exported as part of the default export.

has_assets: optional boolean

Whether a Worker contains assets.

has_modules: optional boolean

Whether a Worker contains modules.

last_deployed_from: optional string

The client most recently used to deploy this Worker.

logpush: optional boolean

Whether Logpush is turned on for the Worker.

migration_tag: optional string

The tag of the Durable Object migration that was most recently applied for this Worker.

modified_on: optional string

When the script was last modified.

formatdate-time
named_handlers: optional array of { handlers, name }

Named exports, such as Durable Object class implementations and named entrypoints.

handlers: optional array of string

The names of handlers exported as part of the named export.

name: optional string

The name of the export.

observability: optional { enabled, head_sampling_rate, logs, traces }

Observability settings for the Worker.

enabled: boolean

Whether observability is enabled for the Worker.

head_sampling_rate: optional number

The sampling rate for incoming requests. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

logs: optional { enabled, invocation_logs, destinations, 2 more }

Log settings for the Worker.

enabled: boolean

Whether logs are enabled for the Worker.

invocation_logs: boolean

Whether invocation logs are enabled for the Worker.

destinations: optional array of string

A list of destinations where logs will be exported to.

head_sampling_rate: optional number

The sampling rate for logs. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

persist: optional boolean

Whether log persistence is enabled for the Worker.

traces: optional { destinations, enabled, head_sampling_rate, persist }

Trace settings for the Worker.

destinations: optional array of string

A list of destinations where traces will be exported to.

enabled: optional boolean

Whether traces are enabled for the Worker.

head_sampling_rate: optional number

The sampling rate for traces. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

persist: optional boolean

Whether trace persistence is enabled for the Worker.

placement: optional { mode, last_analyzed_at, status } or { region, last_analyzed_at, status } or { hostname, last_analyzed_at, status } or 5 more

Configuration for Smart Placement. Specify mode=‘smart’ for Smart Placement, or one of region/hostname/host.

One of the following:
{ mode, last_analyzed_at, status }
mode: "smart"
last_analyzed_at: optional string

The last time the script was analyzed for Smart Placement.

formatdate-time
status: optional "SUCCESS" or "UNSUPPORTED_APPLICATION" or "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
{ region, last_analyzed_at, status }
region: string

Cloud region for targeted placement in format ‘provider:region’.

last_analyzed_at: optional string

The last time the script was analyzed for Smart Placement.

formatdate-time
status: optional "SUCCESS" or "UNSUPPORTED_APPLICATION" or "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
{ hostname, last_analyzed_at, status }
hostname: string

HTTP hostname for targeted placement.

last_analyzed_at: optional string

The last time the script was analyzed for Smart Placement.

formatdate-time
status: optional "SUCCESS" or "UNSUPPORTED_APPLICATION" or "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
{ host, last_analyzed_at, status }
host: string

TCP host and port for targeted placement.

last_analyzed_at: optional string

The last time the script was analyzed for Smart Placement.

formatdate-time
status: optional "SUCCESS" or "UNSUPPORTED_APPLICATION" or "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
{ mode, region, last_analyzed_at, status }
mode: "targeted"

Targeted placement mode.

region: string

Cloud region for targeted placement in format ‘provider:region’.

last_analyzed_at: optional string

The last time the script was analyzed for Smart Placement.

formatdate-time
status: optional "SUCCESS" or "UNSUPPORTED_APPLICATION" or "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
{ hostname, mode, last_analyzed_at, status }
hostname: string

HTTP hostname for targeted placement.

mode: "targeted"

Targeted placement mode.

last_analyzed_at: optional string

The last time the script was analyzed for Smart Placement.

formatdate-time
status: optional "SUCCESS" or "UNSUPPORTED_APPLICATION" or "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
{ host, mode, last_analyzed_at, status }
host: string

TCP host and port for targeted placement.

mode: "targeted"

Targeted placement mode.

last_analyzed_at: optional string

The last time the script was analyzed for Smart Placement.

formatdate-time
status: optional "SUCCESS" or "UNSUPPORTED_APPLICATION" or "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
{ mode, target, last_analyzed_at, status }
mode: "targeted"

Targeted placement mode.

target: array of { region } or { hostname } or { host }

Array of placement targets (currently limited to single target).

One of the following:
Region { region }
region: string

Cloud region in format ‘provider:region’.

Hostname { hostname }
hostname: string

HTTP hostname for targeted placement.

Host { host }
host: string

TCP host:port for targeted placement.

last_analyzed_at: optional string

The last time the script was analyzed for Smart Placement.

formatdate-time
status: optional "SUCCESS" or "UNSUPPORTED_APPLICATION" or "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
Deprecatedplacement_mode: optional "smart" or "targeted"

Configuration for Smart Placement. Specify mode=‘smart’ for Smart Placement, or one of region/hostname/host.

One of the following:
"smart"
"targeted"
Deprecatedplacement_status: optional "SUCCESS" or "UNSUPPORTED_APPLICATION" or "INSUFFICIENT_INVOCATIONS"

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
tag: optional string

The immutable ID of the script.

tags: optional array of string

Tags associated with the Worker.

tail_consumers: optional array of ConsumerScript { service, environment, namespace }

List of Workers that will consume logs from the attached Worker.

service: string

Name of Worker that is to be the consumer.

environment: optional string

Optional environment if the Worker utilizes one.

namespace: optional string

Optional dispatch namespace the script belongs to.

usage_model: optional "standard" or "bundled" or "unbound"

Usage model for the Worker invocations.

One of the following:
"standard"
"bundled"
"unbound"
success: true

Whether the API call was successful.

Put script content

curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/workers/scripts/$SCRIPT_NAME/content \
    -X PUT \
    -H 'Content-Type: multipart/form-data' \
    -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
    -F metadata='{}'
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "id": "my-workers-script",
    "compatibility_date": "2021-01-01",
    "compatibility_flags": [
      "nodejs_compat"
    ],
    "created_on": "2017-01-01T00:00:00Z",
    "etag": "ea95132c15732412d22c1476fa83f27a",
    "handlers": [
      "fetch",
      "scheduled"
    ],
    "has_assets": false,
    "has_modules": false,
    "last_deployed_from": "wrangler",
    "logpush": false,
    "migration_tag": "v1",
    "modified_on": "2017-01-01T00:00:00Z",
    "named_handlers": [
      {
        "handlers": [
          "class"
        ],
        "name": "MyDurableObject"
      }
    ],
    "observability": {
      "enabled": true,
      "head_sampling_rate": 0.1,
      "logs": {
        "enabled": true,
        "invocation_logs": true,
        "destinations": [
          "cloudflare"
        ],
        "head_sampling_rate": 0.1,
        "persist": true
      },
      "traces": {
        "destinations": [
          "cloudflare"
        ],
        "enabled": true,
        "head_sampling_rate": 0.1,
        "persist": true
      }
    },
    "placement": {
      "mode": "smart",
      "last_analyzed_at": "2025-01-01T00:00:00Z",
      "status": "SUCCESS"
    },
    "placement_mode": "smart",
    "placement_status": "SUCCESS",
    "tag": "e8f70fdbc8b1fb0b8ddb1af166186758",
    "tags": [
      "my-team",
      "my-public-api"
    ],
    "tail_consumers": [
      {
        "service": "my-log-consumer",
        "environment": "production",
        "namespace": "my-namespace"
      }
    ],
    "usage_model": "standard"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "id": "my-workers-script",
    "compatibility_date": "2021-01-01",
    "compatibility_flags": [
      "nodejs_compat"
    ],
    "created_on": "2017-01-01T00:00:00Z",
    "etag": "ea95132c15732412d22c1476fa83f27a",
    "handlers": [
      "fetch",
      "scheduled"
    ],
    "has_assets": false,
    "has_modules": false,
    "last_deployed_from": "wrangler",
    "logpush": false,
    "migration_tag": "v1",
    "modified_on": "2017-01-01T00:00:00Z",
    "named_handlers": [
      {
        "handlers": [
          "class"
        ],
        "name": "MyDurableObject"
      }
    ],
    "observability": {
      "enabled": true,
      "head_sampling_rate": 0.1,
      "logs": {
        "enabled": true,
        "invocation_logs": true,
        "destinations": [
          "cloudflare"
        ],
        "head_sampling_rate": 0.1,
        "persist": true
      },
      "traces": {
        "destinations": [
          "cloudflare"
        ],
        "enabled": true,
        "head_sampling_rate": 0.1,
        "persist": true
      }
    },
    "placement": {
      "mode": "smart",
      "last_analyzed_at": "2025-01-01T00:00:00Z",
      "status": "SUCCESS"
    },
    "placement_mode": "smart",
    "placement_status": "SUCCESS",
    "tag": "e8f70fdbc8b1fb0b8ddb1af166186758",
    "tags": [
      "my-team",
      "my-public-api"
    ],
    "tail_consumers": [
      {
        "service": "my-log-consumer",
        "environment": "production",
        "namespace": "my-namespace"
      }
    ],
    "usage_model": "standard"
  },
  "success": true
}