Skip to content
Start here

Update Worker

client.Workers.Beta.Workers.Update(ctx, workerID, params) (*Worker, error)
PUT/accounts/{account_id}/workers/workers/{worker_id}

Perform a complete replacement of a Worker, where omitted properties are set to their default values. This is the exact same as the Create Worker endpoint, but operates on an existing Worker. To perform a partial update instead, use the Edit Worker endpoint.

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
workerID string

Identifier for the Worker, which can be ID or name.

params BetaWorkerUpdateParams
AccountID param.Field[string]

Path param: Identifier.

maxLength32
Worker param.Field[Worker]

Body param

ReturnsExpand Collapse
type Worker struct{…}
ID string

Immutable ID of the Worker.

CreatedOn Time

When the Worker was created.

formatdate-time
Logpush bool

Whether logpush is enabled for the Worker.

Name string

Name of the Worker.

Observability WorkerObservability

Observability settings for the Worker.

Enabled boolOptional

Whether observability is enabled for the Worker.

HeadSamplingRate float64Optional

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

Issues WorkerObservabilityIssuesOptional

Real-time Issues settings for the Worker.

Enabled boolOptional

Whether real-time Issues are enabled for the Worker.

Logs WorkerObservabilityLogsOptional

Log settings for the Worker.

Destinations []stringOptional

A list of destinations where logs will be exported to.

Enabled boolOptional

Whether logs are enabled for the Worker.

HeadSamplingRate float64Optional

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

InvocationLogs boolOptional

Whether invocation logs are enabled for the Worker.

Persist boolOptional

Whether log persistence is enabled for the Worker.

RedactQueryString boolOptional

Whether query strings are removed from request URLs in logs and traces.

Traces WorkerObservabilityTracesOptional

Trace settings for the Worker.

Destinations []stringOptional

A list of destinations where traces will be exported to.

Enabled boolOptional

Whether traces are enabled for the Worker.

HeadSamplingRate float64Optional

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

Persist boolOptional

Whether trace persistence is enabled for the Worker.

PropagationPolicy WorkerObservabilityTracesPropagationPolicyOptional

Controls how inbound trace context (traceparent/tracestate) headers on incoming requests are handled. “authenticated” honors inbound trace context only when accompanied by a valid trace auth token. “accept” unconditionally accepts inbound trace context. Requires the trace propagation feature to be enabled. Returns null when the trace propagation feature is not enabled for the account.

One of the following:
const WorkerObservabilityTracesPropagationPolicyAuthenticated WorkerObservabilityTracesPropagationPolicy = "authenticated"
const WorkerObservabilityTracesPropagationPolicyAccept WorkerObservabilityTracesPropagationPolicy = "accept"
References WorkerReferences

Other resources that reference the Worker and depend on it existing.

DispatchNamespaceOutbounds []WorkerReferencesDispatchNamespaceOutbound

Other Workers that reference the Worker as an outbound for a dispatch namespace.

NamespaceID string

ID of the dispatch namespace.

NamespaceName string

Name of the dispatch namespace.

WorkerID string

ID of the Worker using the dispatch namespace.

WorkerName string

Name of the Worker using the dispatch namespace.

Domains []WorkerReferencesDomain

Custom domains connected to the Worker.

ID string

ID of the custom domain.

CertificateID string

ID of the TLS certificate issued for the custom domain.

Hostname string

Full hostname of the custom domain, including the zone name.

ZoneID string

ID of the zone.

ZoneName string

Name of the zone.

DurableObjects []WorkerReferencesDurableObject

Other Workers that reference Durable Object classes implemented by the Worker.

NamespaceID string

ID of the Durable Object namespace being used.

NamespaceName string

Name of the Durable Object namespace being used.

WorkerID string

ID of the Worker using the Durable Object implementation.

WorkerName string

Name of the Worker using the Durable Object implementation.

Queues []WorkerReferencesQueue

Queues that send messages to the Worker.

QueueConsumerID string

ID of the queue consumer configuration.

QueueID string

ID of the queue.

QueueName string

Name of the queue.

Workers []WorkerReferencesWorker

Other Workers that reference the Worker using service bindings.

ID string

ID of the referencing Worker.

Name string

Name of the referencing Worker.

Subdomain WorkerSubdomain

Subdomain settings for the Worker.

Enabled boolOptional

Whether the *.workers.dev subdomain is enabled for the Worker.

PreviewURLSuffix stringOptional

Prepend a version or preview prefix to this host suffix to form the *.workers.dev preview URL the Worker would serve on once previews are enabled, e.g. https://<prefix>-my-worker.my-subdomain.workers.dev. Present whenever the account owns a workers.dev subdomain, regardless of whether previews_enabled is true, so presence does not imply preview URLs are currently live. Absent only when the account owns no workers.dev subdomain.

PreviewsEnabled boolOptional

Whether preview URLs are enabled for the Worker.

URL stringOptional

The address the Worker would serve on once its *.workers.dev subdomain is enabled. Present whenever the account owns a workers.dev subdomain, regardless of whether enabled is true, so presence does not imply the Worker is currently live at this URL. Absent only when the account owns no workers.dev subdomain.

formaturi
Tags []string

Tags associated with the Worker.

TailConsumers []WorkerTailConsumer

Other Workers that should consume logs from the Worker.

Name string

Name of the consumer Worker.

UpdatedOn Time

When the Worker was most recently updated.

formatdate-time
DeployedOn TimeOptional

When the Worker’s most recent deployment was created. null if the Worker has never been deployed.

formatdate-time
PreviewsBaseConfig WorkerPreviewsBaseConfigOptional

Template configuration used when creating new Previews for this Worker.

CacheOptions WorkerPreviewsBaseConfigCacheOptionsOptional

Cache options used when creating new Previews.

Enabled bool

Whether caching is enabled for this Worker.

CrossVersionCache boolOptional

Whether cached responses are shared across Worker version uploads. This is independent of enabled. It can stay true while caching is off, so the preference survives turning caching off and back on.

Env map[string, WorkerPreviewsBaseConfigEnv]Optional

Bindings used when creating new Previews, keyed by binding name.

Type string

The kind of resource that the binding provides.

Limits WorkerPreviewsBaseConfigLimitsOptional

Resource limits enforced at runtime for newly created Previews.

CPUMs int64Optional

The amount of CPU time this Worker can use in milliseconds.

Subrequests int64Optional

The number of subrequests this Worker can make per request.

Logpush boolOptional

Whether logpush is enabled when creating new Previews.

Observability WorkerPreviewsBaseConfigObservabilityOptional

Observability settings used when creating new Previews.

Enabled boolOptional

Whether observability is enabled for the Worker.

HeadSamplingRate float64Optional

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

Issues WorkerPreviewsBaseConfigObservabilityIssuesOptional

Real-time Issues settings for the Worker.

Enabled boolOptional

Whether real-time Issues are enabled for the Worker.

Logs WorkerPreviewsBaseConfigObservabilityLogsOptional

Log settings for the Worker.

Destinations []stringOptional

A list of destinations where logs will be exported to.

Enabled boolOptional

Whether logs are enabled for the Worker.

HeadSamplingRate float64Optional

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

InvocationLogs boolOptional

Whether invocation logs are enabled for the Worker.

Persist boolOptional

Whether log persistence is enabled for the Worker.

RedactQueryString boolOptional

Whether query strings are removed from request URLs in logs and traces.

Traces WorkerPreviewsBaseConfigObservabilityTracesOptional

Trace settings for the Worker.

Destinations []stringOptional

A list of destinations where traces will be exported to.

Enabled boolOptional

Whether traces are enabled for the Worker.

HeadSamplingRate float64Optional

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

Persist boolOptional

Whether trace persistence is enabled for the Worker.

PropagationPolicy WorkerPreviewsBaseConfigObservabilityTracesPropagationPolicyOptional

Controls how inbound trace context (traceparent/tracestate) headers on incoming requests are handled. “authenticated” honors inbound trace context only when accompanied by a valid trace auth token. “accept” unconditionally accepts inbound trace context. Requires the trace propagation feature to be enabled. Returns null when the trace propagation feature is not enabled for the account.

One of the following:
const WorkerPreviewsBaseConfigObservabilityTracesPropagationPolicyAuthenticated WorkerPreviewsBaseConfigObservabilityTracesPropagationPolicy = "authenticated"
const WorkerPreviewsBaseConfigObservabilityTracesPropagationPolicyAccept WorkerPreviewsBaseConfigObservabilityTracesPropagationPolicy = "accept"
Placement WorkerPreviewsBaseConfigPlacementOptional

Placement configuration used when creating new Previews.

One of the following:
type WorkerPreviewsBaseConfigPlacementMode struct{…}
Mode WorkerPreviewsBaseConfigPlacementModeMode
type WorkerPreviewsBaseConfigPlacementRegion struct{…}
Region string

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

type WorkerPreviewsBaseConfigPlacementHostname struct{…}
Hostname string

HTTP hostname for targeted placement.

type WorkerPreviewsBaseConfigPlacementHost struct{…}
Host string

TCP host and port for targeted placement.

type WorkerPreviewsBaseConfigPlacementObject struct{…}
Mode WorkerPreviewsBaseConfigPlacementObjectMode

Targeted placement mode.

Region string

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

type WorkerPreviewsBaseConfigPlacementObject struct{…}
Hostname string

HTTP hostname for targeted placement.

Mode WorkerPreviewsBaseConfigPlacementObjectMode

Targeted placement mode.

type WorkerPreviewsBaseConfigPlacementObject struct{…}
Host string

TCP host and port for targeted placement.

Mode WorkerPreviewsBaseConfigPlacementObjectMode

Targeted placement mode.

type WorkerPreviewsBaseConfigPlacementObject struct{…}
Mode WorkerPreviewsBaseConfigPlacementObjectMode

Targeted placement mode.

Target []WorkerPreviewsBaseConfigPlacementObjectTarget

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

One of the following:
type WorkerPreviewsBaseConfigPlacementObjectTargetRegion struct{…}
Region string

Cloud region in format ‘provider:region’.

type WorkerPreviewsBaseConfigPlacementObjectTargetHostname struct{…}
Hostname string

HTTP hostname for targeted placement.

type WorkerPreviewsBaseConfigPlacementObjectTargetHost struct{…}
Host string

TCP host:port for targeted placement.

TailConsumers []WorkerPreviewsBaseConfigTailConsumerOptional

Other Workers that should consume logs from newly created Previews.

Name string

Name of the consumer Worker.

Update Worker

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/option"
  "github.com/cloudflare/cloudflare-go/workers"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  worker, err := client.Workers.Beta.Workers.Update(
    context.TODO(),
    "worker_id",
    workers.BetaWorkerUpdateParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
      Worker: workers.WorkerParam{
        Logpush: cloudflare.F(true),
        Name: cloudflare.F("my-worker"),
        Observability: cloudflare.F(workers.WorkerObservabilityParam{

        }),
        Subdomain: cloudflare.F(workers.WorkerSubdomainParam{

        }),
        Tags: cloudflare.F([]string{"my-team", "my-public-api"}),
        TailConsumers: cloudflare.F([]workers.WorkerTailConsumerParam{workers.WorkerTailConsumerParam{
          Name: cloudflare.F("my-tail-consumer"),
        }}),
      },
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", worker.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": "e8f70fdbc8b1fb0b8ddb1af166186758",
    "created_on": "2019-12-27T18:11:19.117Z",
    "logpush": true,
    "name": "my-worker",
    "observability": {
      "enabled": true,
      "head_sampling_rate": 1,
      "issues": {
        "enabled": true
      },
      "logs": {
        "destinations": [
          "string"
        ],
        "enabled": true,
        "head_sampling_rate": 1,
        "invocation_logs": true,
        "persist": true
      },
      "redact_query_string": true,
      "traces": {
        "destinations": [
          "string"
        ],
        "enabled": true,
        "head_sampling_rate": 1,
        "persist": true,
        "propagation_policy": "authenticated"
      }
    },
    "references": {
      "dispatch_namespace_outbounds": [
        {
          "namespace_id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "namespace_name": "my-dispatch-namespace",
          "worker_id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "worker_name": "my-worker"
        }
      ],
      "domains": [
        {
          "id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "certificate_id": "certificate_id",
          "hostname": "my-worker.example.com",
          "zone_id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "zone_name": "example.com"
        }
      ],
      "durable_objects": [
        {
          "namespace_id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "namespace_name": "my-durable-object-namespace",
          "worker_id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "worker_name": "my-worker"
        }
      ],
      "queues": [
        {
          "queue_consumer_id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "queue_id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "queue_name": "my-queue"
        }
      ],
      "workers": [
        {
          "id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "name": "my-worker"
        }
      ]
    },
    "subdomain": {
      "enabled": true,
      "preview_url_suffix": "-my-worker.my-subdomain.workers.dev",
      "previews_enabled": true,
      "url": "https://my-worker.my-subdomain.workers.dev"
    },
    "tags": [
      "my-team",
      "my-public-api"
    ],
    "tail_consumers": [
      {
        "name": "my-tail-consumer"
      }
    ],
    "updated_on": "2019-12-27T18:11:19.117Z",
    "deployed_on": "2019-12-27T18:11:19.117Z",
    "previews_base_config": {
      "cache_options": {
        "enabled": true,
        "cross_version_cache": true
      },
      "env": {
        "MY_ENV_VAR": {
          "type": "plain_text"
        }
      },
      "limits": {
        "cpu_ms": 50,
        "subrequests": 1000
      },
      "logpush": true,
      "observability": {
        "enabled": true,
        "head_sampling_rate": 1,
        "issues": {
          "enabled": true
        },
        "logs": {
          "destinations": [
            "string"
          ],
          "enabled": true,
          "head_sampling_rate": 1,
          "invocation_logs": true,
          "persist": true
        },
        "redact_query_string": true,
        "traces": {
          "destinations": [
            "string"
          ],
          "enabled": true,
          "head_sampling_rate": 1,
          "persist": true,
          "propagation_policy": "authenticated"
        }
      },
      "placement": {
        "mode": "smart"
      },
      "tail_consumers": [
        {
          "name": "my-tail-consumer"
        }
      ]
    }
  },
  "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": "e8f70fdbc8b1fb0b8ddb1af166186758",
    "created_on": "2019-12-27T18:11:19.117Z",
    "logpush": true,
    "name": "my-worker",
    "observability": {
      "enabled": true,
      "head_sampling_rate": 1,
      "issues": {
        "enabled": true
      },
      "logs": {
        "destinations": [
          "string"
        ],
        "enabled": true,
        "head_sampling_rate": 1,
        "invocation_logs": true,
        "persist": true
      },
      "redact_query_string": true,
      "traces": {
        "destinations": [
          "string"
        ],
        "enabled": true,
        "head_sampling_rate": 1,
        "persist": true,
        "propagation_policy": "authenticated"
      }
    },
    "references": {
      "dispatch_namespace_outbounds": [
        {
          "namespace_id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "namespace_name": "my-dispatch-namespace",
          "worker_id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "worker_name": "my-worker"
        }
      ],
      "domains": [
        {
          "id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "certificate_id": "certificate_id",
          "hostname": "my-worker.example.com",
          "zone_id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "zone_name": "example.com"
        }
      ],
      "durable_objects": [
        {
          "namespace_id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "namespace_name": "my-durable-object-namespace",
          "worker_id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "worker_name": "my-worker"
        }
      ],
      "queues": [
        {
          "queue_consumer_id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "queue_id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "queue_name": "my-queue"
        }
      ],
      "workers": [
        {
          "id": "e8f70fdbc8b1fb0b8ddb1af166186758",
          "name": "my-worker"
        }
      ]
    },
    "subdomain": {
      "enabled": true,
      "preview_url_suffix": "-my-worker.my-subdomain.workers.dev",
      "previews_enabled": true,
      "url": "https://my-worker.my-subdomain.workers.dev"
    },
    "tags": [
      "my-team",
      "my-public-api"
    ],
    "tail_consumers": [
      {
        "name": "my-tail-consumer"
      }
    ],
    "updated_on": "2019-12-27T18:11:19.117Z",
    "deployed_on": "2019-12-27T18:11:19.117Z",
    "previews_base_config": {
      "cache_options": {
        "enabled": true,
        "cross_version_cache": true
      },
      "env": {
        "MY_ENV_VAR": {
          "type": "plain_text"
        }
      },
      "limits": {
        "cpu_ms": 50,
        "subrequests": 1000
      },
      "logpush": true,
      "observability": {
        "enabled": true,
        "head_sampling_rate": 1,
        "issues": {
          "enabled": true
        },
        "logs": {
          "destinations": [
            "string"
          ],
          "enabled": true,
          "head_sampling_rate": 1,
          "invocation_logs": true,
          "persist": true
        },
        "redact_query_string": true,
        "traces": {
          "destinations": [
            "string"
          ],
          "enabled": true,
          "head_sampling_rate": 1,
          "persist": true,
          "propagation_policy": "authenticated"
        }
      },
      "placement": {
        "mode": "smart"
      },
      "tail_consumers": [
        {
          "name": "my-tail-consumer"
        }
      ]
    }
  },
  "success": true
}