Skip to content
Start here

Put Script Content

workers_for_platforms.dispatch.namespaces.scripts.content.update(strscript_name, ContentUpdateParams**kwargs) -> Script
PUT/accounts/{account_id}/workers/dispatch/namespaces/{dispatch_namespace}/scripts/{script_name}/content

Put script content for a script uploaded to a Workers for Platforms namespace.

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
ParametersExpand Collapse
account_id: str

Identifier.

maxLength32
dispatch_namespace: str

Name of the Workers for Platforms dispatch namespace.

script_name: str

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

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

body_part: Optional[str]

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

main_module: Optional[str]

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

files: Optional[Sequence[FileTypes]]

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.

cf_worker_body_part: Optional[str]
cf_worker_main_module_part: Optional[str]
ReturnsExpand Collapse
class Script:
id: Optional[str]

The name used to identify the script.

compatibility_date: Optional[str]

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[List[str]]

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[datetime]

When the script was created.

formatdate-time
etag: Optional[str]

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

handlers: Optional[List[str]]

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

has_assets: Optional[bool]

Whether a Worker contains assets.

has_modules: Optional[bool]

Whether a Worker contains modules.

last_deployed_from: Optional[str]

The client most recently used to deploy this Worker.

logpush: Optional[bool]

Whether Logpush is turned on for the Worker.

migration_tag: Optional[str]

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

modified_on: Optional[datetime]

When the script was last modified.

formatdate-time
named_handlers: Optional[List[NamedHandler]]

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

handlers: Optional[List[str]]

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

name: Optional[str]

The name of the export.

observability: Optional[Observability]

Observability settings for the Worker.

enabled: bool

Whether observability is enabled for the Worker.

head_sampling_rate: Optional[float]

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

logs: Optional[ObservabilityLogs]

Log settings for the Worker.

enabled: bool

Whether logs are enabled for the Worker.

invocation_logs: bool

Whether invocation logs are enabled for the Worker.

destinations: Optional[List[str]]

A list of destinations where logs will be exported to.

head_sampling_rate: Optional[float]

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

persist: Optional[bool]

Whether log persistence is enabled for the Worker.

traces: Optional[ObservabilityTraces]

Trace settings for the Worker.

destinations: Optional[List[str]]

A list of destinations where traces will be exported to.

enabled: Optional[bool]

Whether traces are enabled for the Worker.

head_sampling_rate: Optional[float]

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

persist: Optional[bool]

Whether trace persistence is enabled for the Worker.

placement: Optional[Placement]

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

One of the following:
class PlacementUnionMember0:
mode: Literal["smart"]
last_analyzed_at: Optional[datetime]

The last time the script was analyzed for Smart Placement.

formatdate-time
status: Optional[Literal["SUCCESS", "UNSUPPORTED_APPLICATION", "INSUFFICIENT_INVOCATIONS"]]

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
class PlacementUnionMember1:
region: str

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

last_analyzed_at: Optional[datetime]

The last time the script was analyzed for Smart Placement.

formatdate-time
status: Optional[Literal["SUCCESS", "UNSUPPORTED_APPLICATION", "INSUFFICIENT_INVOCATIONS"]]

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
class PlacementUnionMember2:
hostname: str

HTTP hostname for targeted placement.

last_analyzed_at: Optional[datetime]

The last time the script was analyzed for Smart Placement.

formatdate-time
status: Optional[Literal["SUCCESS", "UNSUPPORTED_APPLICATION", "INSUFFICIENT_INVOCATIONS"]]

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
class PlacementUnionMember3:
host: str

TCP host and port for targeted placement.

last_analyzed_at: Optional[datetime]

The last time the script was analyzed for Smart Placement.

formatdate-time
status: Optional[Literal["SUCCESS", "UNSUPPORTED_APPLICATION", "INSUFFICIENT_INVOCATIONS"]]

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
class PlacementUnionMember4:
mode: Literal["targeted"]

Targeted placement mode.

region: str

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

last_analyzed_at: Optional[datetime]

The last time the script was analyzed for Smart Placement.

formatdate-time
status: Optional[Literal["SUCCESS", "UNSUPPORTED_APPLICATION", "INSUFFICIENT_INVOCATIONS"]]

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
class PlacementUnionMember5:
hostname: str

HTTP hostname for targeted placement.

mode: Literal["targeted"]

Targeted placement mode.

last_analyzed_at: Optional[datetime]

The last time the script was analyzed for Smart Placement.

formatdate-time
status: Optional[Literal["SUCCESS", "UNSUPPORTED_APPLICATION", "INSUFFICIENT_INVOCATIONS"]]

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
class PlacementUnionMember6:
host: str

TCP host and port for targeted placement.

mode: Literal["targeted"]

Targeted placement mode.

last_analyzed_at: Optional[datetime]

The last time the script was analyzed for Smart Placement.

formatdate-time
status: Optional[Literal["SUCCESS", "UNSUPPORTED_APPLICATION", "INSUFFICIENT_INVOCATIONS"]]

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
class PlacementUnionMember7:
mode: Literal["targeted"]

Targeted placement mode.

target: List[PlacementUnionMember7Target]

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

One of the following:
class PlacementUnionMember7TargetRegion:
region: str

Cloud region in format ‘provider:region’.

class PlacementUnionMember7TargetHostname:
hostname: str

HTTP hostname for targeted placement.

class PlacementUnionMember7TargetHost:
host: str

TCP host:port for targeted placement.

last_analyzed_at: Optional[datetime]

The last time the script was analyzed for Smart Placement.

formatdate-time
status: Optional[Literal["SUCCESS", "UNSUPPORTED_APPLICATION", "INSUFFICIENT_INVOCATIONS"]]

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
Deprecatedplacement_mode: Optional[Literal["smart", "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[Literal["SUCCESS", "UNSUPPORTED_APPLICATION", "INSUFFICIENT_INVOCATIONS"]]

Status of Smart Placement.

One of the following:
"SUCCESS"
"UNSUPPORTED_APPLICATION"
"INSUFFICIENT_INVOCATIONS"
tag: Optional[str]

The immutable ID of the script.

tags: Optional[List[str]]

Tags associated with the Worker.

tail_consumers: Optional[List[ConsumerScript]]

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

service: str

Name of Worker that is to be the consumer.

environment: Optional[str]

Optional environment if the Worker utilizes one.

namespace: Optional[str]

Optional dispatch namespace the script belongs to.

usage_model: Optional[Literal["standard", "bundled", "unbound"]]

Usage model for the Worker invocations.

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

Put Script Content

import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
script = client.workers_for_platforms.dispatch.namespaces.scripts.content.update(
    script_name="this-is_my_script-01",
    account_id="023e105f4ecef8ad9ca31a8372d0c353",
    dispatch_namespace="my-dispatch-namespace",
    metadata={},
)
print(script.id)
{
  "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
}