Skip to content
Start here

Create Event Subscription

client.Queues.Subscriptions.New(ctx, params) (*SubscriptionNewResponse, error)
POST/accounts/{account_id}/event_subscriptions/subscriptions

Create a new event subscription for a queue

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)
Queues WriteWorkers Scripts Write
ParametersExpand Collapse
params SubscriptionNewParams
AccountID param.Field[string]

Path param: A Resource identifier.

maxLength32
Destination param.Field[SubscriptionNewParamsDestination]optional

Body param: Destination configuration for the subscription

QueueID string

ID of the target queue

Type SubscriptionNewParamsDestinationType

Type of destination

Enabled param.Field[bool]optional

Body param: Whether the subscription is active

Events param.Field[[]string]optional

Body param: List of event types this subscription handles

Name param.Field[string]optional

Body param: Name of the subscription

Source param.Field[SubscriptionNewParamsSource]optional

Body param: Source configuration for the subscription

type SubscriptionNewParamsSourceMqEventSourceImages struct{…}
Type SubscriptionNewParamsSourceMqEventSourceImagesTypeoptional

Type of source

type SubscriptionNewParamsSourceMqEventSourceKV struct{…}
Type SubscriptionNewParamsSourceMqEventSourceKVTypeoptional

Type of source

type SubscriptionNewParamsSourceMqEventSourceR2 struct{…}
Type SubscriptionNewParamsSourceMqEventSourceR2Typeoptional

Type of source

type SubscriptionNewParamsSourceMqEventSourceSuperSlurper struct{…}
Type SubscriptionNewParamsSourceMqEventSourceSuperSlurperTypeoptional

Type of source

type SubscriptionNewParamsSourceMqEventSourceVectorize struct{…}
Type SubscriptionNewParamsSourceMqEventSourceVectorizeTypeoptional

Type of source

type SubscriptionNewParamsSourceMqEventSourceWorkersAIModel struct{…}
ModelName stringoptional

Name of the Workers AI model

Type SubscriptionNewParamsSourceMqEventSourceWorkersAIModelTypeoptional

Type of source

type SubscriptionNewParamsSourceMqEventSourceWorkersBuildsWorker struct{…}
Type SubscriptionNewParamsSourceMqEventSourceWorkersBuildsWorkerTypeoptional

Type of source

WorkerName stringoptional

Name of the worker

type SubscriptionNewParamsSourceMqEventSourceWorkflowsWorkflow struct{…}
Type SubscriptionNewParamsSourceMqEventSourceWorkflowsWorkflowTypeoptional

Type of source

WorkflowName stringoptional

Name of the workflow

ReturnsExpand Collapse
type SubscriptionNewResponse struct{…}
ID string

Unique identifier for the subscription

CreatedAt Time

When the subscription was created

formatdate-time
Destination SubscriptionNewResponseDestination

Destination configuration for the subscription

QueueID string

ID of the target queue

Type SubscriptionNewResponseDestinationType

Type of destination

Enabled bool

Whether the subscription is active

Events []string

List of event types this subscription handles

ModifiedAt Time

When the subscription was last modified

formatdate-time
Name string

Name of the subscription

Source SubscriptionNewResponseSource

Source configuration for the subscription

One of the following:
type SubscriptionNewResponseSourceMqEventSourceImages struct{…}
Type SubscriptionNewResponseSourceMqEventSourceImagesTypeoptional

Type of source

type SubscriptionNewResponseSourceMqEventSourceKV struct{…}
Type SubscriptionNewResponseSourceMqEventSourceKVTypeoptional

Type of source

type SubscriptionNewResponseSourceMqEventSourceR2 struct{…}
Type SubscriptionNewResponseSourceMqEventSourceR2Typeoptional

Type of source

type SubscriptionNewResponseSourceMqEventSourceSuperSlurper struct{…}
Type SubscriptionNewResponseSourceMqEventSourceSuperSlurperTypeoptional

Type of source

type SubscriptionNewResponseSourceMqEventSourceVectorize struct{…}
Type SubscriptionNewResponseSourceMqEventSourceVectorizeTypeoptional

Type of source

type SubscriptionNewResponseSourceMqEventSourceWorkersAIModel struct{…}
ModelName stringoptional

Name of the Workers AI model

Type SubscriptionNewResponseSourceMqEventSourceWorkersAIModelTypeoptional

Type of source

type SubscriptionNewResponseSourceMqEventSourceWorkersBuildsWorker struct{…}
Type SubscriptionNewResponseSourceMqEventSourceWorkersBuildsWorkerTypeoptional

Type of source

WorkerName stringoptional

Name of the worker

type SubscriptionNewResponseSourceMqEventSourceWorkflowsWorkflow struct{…}
Type SubscriptionNewResponseSourceMqEventSourceWorkflowsWorkflowTypeoptional

Type of source

WorkflowName stringoptional

Name of the workflow

Create Event Subscription

package main

import (
  "context"
  "fmt"

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

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  subscription, err := client.Queues.Subscriptions.New(context.TODO(), queues.SubscriptionNewParams{
    AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", subscription.ID)
}
{
  "errors": [
    {
      "code": 7003,
      "message": "No route for the URI",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "id": "id",
    "created_at": "2019-12-27T18:11:19.117Z",
    "destination": {
      "queue_id": "queue_id",
      "type": "queues.queue"
    },
    "enabled": true,
    "events": [
      "string"
    ],
    "modified_at": "2019-12-27T18:11:19.117Z",
    "name": "name",
    "source": {
      "type": "images"
    }
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 7003,
      "message": "No route for the URI",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "id": "id",
    "created_at": "2019-12-27T18:11:19.117Z",
    "destination": {
      "queue_id": "queue_id",
      "type": "queues.queue"
    },
    "enabled": true,
    "events": [
      "string"
    ],
    "modified_at": "2019-12-27T18:11:19.117Z",
    "name": "name",
    "source": {
      "type": "images"
    }
  },
  "success": true
}