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%).

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.

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.

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.

PreviewsEnabled booloptional

Whether preview URLs are enabled for the Worker.

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

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,
      "logs": {
        "destinations": [
          "string"
        ],
        "enabled": true,
        "head_sampling_rate": 1,
        "invocation_logs": true,
        "persist": true
      },
      "traces": {
        "destinations": [
          "string"
        ],
        "enabled": true,
        "head_sampling_rate": 1,
        "persist": true
      }
    },
    "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,
      "previews_enabled": true
    },
    "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"
  },
  "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,
      "logs": {
        "destinations": [
          "string"
        ],
        "enabled": true,
        "head_sampling_rate": 1,
        "invocation_logs": true,
        "persist": true
      },
      "traces": {
        "destinations": [
          "string"
        ],
        "enabled": true,
        "head_sampling_rate": 1,
        "persist": true
      }
    },
    "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,
      "previews_enabled": true
    },
    "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"
  },
  "success": true
}