Skip to content
Start here

Purge Queue

client.Queues.Purge.Start(ctx, queueID, params) (*Queue, error)
POST/accounts/{account_id}/queues/{queue_id}/purge

Deletes all messages from the 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
queueID string

A Resource identifier.

maxLength32
params PurgeStartParams
AccountID param.Field[string]

Path param: A Resource identifier.

maxLength32
DeleteMessagesPermanently param.Field[bool]optional

Body param: Confimation that all messages will be deleted permanently.

ReturnsExpand Collapse
type Queue struct{…}
Consumers []Consumeroptional
One of the following:
type ConsumerMqWorkerConsumerResponse struct{…}
ConsumerID stringoptional

A Resource identifier.

maxLength32
CreatedOn Timeoptional
formatdate-time
DeadLetterQueue stringoptional

Name of the dead letter queue, or empty string if not configured

QueueName stringoptional
ScriptName stringoptional

Name of a Worker

Settings ConsumerMqWorkerConsumerResponseSettingsoptional
BatchSize float64optional

The maximum number of messages to include in a batch.

MaxConcurrency float64optional

Maximum number of concurrent consumers that may consume from this Queue. Set to null to automatically opt in to the platform's maximum (recommended).

MaxRetries float64optional

The maximum number of retries

MaxWaitTimeMs float64optional

The number of milliseconds to wait for a batch to fill up before attempting to deliver it

RetryDelay float64optional

The number of seconds to delay before making the message available for another attempt.

Type ConsumerMqWorkerConsumerResponseTypeoptional
type ConsumerMqHTTPConsumerResponse struct{…}
ConsumerID stringoptional

A Resource identifier.

maxLength32
CreatedOn Timeoptional
formatdate-time
DeadLetterQueue stringoptional

Name of the dead letter queue, or empty string if not configured

QueueName stringoptional
Settings ConsumerMqHTTPConsumerResponseSettingsoptional
BatchSize float64optional

The maximum number of messages to include in a batch.

MaxRetries float64optional

The maximum number of retries

RetryDelay float64optional

The number of seconds to delay before making the message available for another attempt.

VisibilityTimeoutMs float64optional

The number of milliseconds that a message is exclusively leased. After the timeout, the message becomes available for another attempt.

Type ConsumerMqHTTPConsumerResponseTypeoptional
ConsumersTotalCount float64optional
CreatedOn stringoptional
ModifiedOn stringoptional
Producers []QueueProduceroptional
One of the following:
type QueueProducersMqWorkerProducer struct{…}
Script stringoptional
Type QueueProducersMqWorkerProducerTypeoptional
type QueueProducersMqR2Producer struct{…}
BucketName stringoptional
Type QueueProducersMqR2ProducerTypeoptional
ProducersTotalCount float64optional
QueueID stringoptional
QueueName stringoptional
Settings QueueSettingsoptional
DeliveryDelay float64optional

Number of seconds to delay delivery of all messages to consumers.

DeliveryPaused booloptional

Indicates if message delivery to consumers is currently paused.

MessageRetentionPeriod float64optional

Number of seconds after which an unconsumed message will be delayed.

Purge Queue

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"),
  )
  queue, err := client.Queues.Purge.Start(
    context.TODO(),
    "023e105f4ecef8ad9ca31a8372d0c353",
    queues.PurgeStartParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", queue.QueueID)
}
{
  "errors": [
    {
      "code": 7003,
      "message": "No route for the URI",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "consumers": [
      {
        "consumer_id": "023e105f4ecef8ad9ca31a8372d0c353",
        "created_on": "2019-12-27T18:11:19.117Z",
        "dead_letter_queue": "dead_letter_queue",
        "queue_name": "example-queue",
        "script_name": "my-consumer-worker",
        "settings": {
          "batch_size": 50,
          "max_concurrency": 10,
          "max_retries": 3,
          "max_wait_time_ms": 5000,
          "retry_delay": 10
        },
        "type": "worker"
      }
    ],
    "consumers_total_count": 0,
    "created_on": "created_on",
    "modified_on": "modified_on",
    "producers": [
      {
        "script": "script",
        "type": "worker"
      }
    ],
    "producers_total_count": 0,
    "queue_id": "queue_id",
    "queue_name": "example-queue",
    "settings": {
      "delivery_delay": 5,
      "delivery_paused": true,
      "message_retention_period": 345600
    }
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 7003,
      "message": "No route for the URI",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "consumers": [
      {
        "consumer_id": "023e105f4ecef8ad9ca31a8372d0c353",
        "created_on": "2019-12-27T18:11:19.117Z",
        "dead_letter_queue": "dead_letter_queue",
        "queue_name": "example-queue",
        "script_name": "my-consumer-worker",
        "settings": {
          "batch_size": 50,
          "max_concurrency": 10,
          "max_retries": 3,
          "max_wait_time_ms": 5000,
          "retry_delay": 10
        },
        "type": "worker"
      }
    ],
    "consumers_total_count": 0,
    "created_on": "created_on",
    "modified_on": "modified_on",
    "producers": [
      {
        "script": "script",
        "type": "worker"
      }
    ],
    "producers_total_count": 0,
    "queue_id": "queue_id",
    "queue_name": "example-queue",
    "settings": {
      "delivery_delay": 5,
      "delivery_paused": true,
      "message_retention_period": 345600
    }
  },
  "success": true
}