Skip to content
Start here

Rotate a token

client.MoQ.Relays.Tokens.Rotate(ctx, relayID, params) (*RelayTokenRotateResponse, error)
POST/accounts/{account_id}/moq/relays/{relay_id}/tokens/rotate

Generates a new token for the specified type. The old token is immediately invalidated. Token value is shown once in the response.

Security

API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
ParametersExpand Collapse
relayID string
params RelayTokenRotateParams
AccountID param.Field[string]

Path param: Cloudflare account identifier.

Type param.Field[RelayTokenRotateParamsType]

Body param: Which token type to rotate.

const RelayTokenRotateParamsTypePublishSubscribe RelayTokenRotateParamsType = "publish_subscribe"
const RelayTokenRotateParamsTypeSubscribe RelayTokenRotateParamsType = "subscribe"
ReturnsExpand Collapse
type RelayTokenRotateResponse struct{…}
Token string

New token value (shown once). Treat as sensitive.

Type RelayTokenRotateResponseType
One of the following:
const RelayTokenRotateResponseTypePublishSubscribe RelayTokenRotateResponseType = "publish_subscribe"
const RelayTokenRotateResponseTypeSubscribe RelayTokenRotateResponseType = "subscribe"

Rotate a token

package main

import (
  "context"
  "fmt"

  "github.com/stainless-sdks/cloudflare-go"
  "github.com/stainless-sdks/cloudflare-go/moq"
  "github.com/stainless-sdks/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  response, err := client.MoQ.Relays.Tokens.Rotate(
    context.TODO(),
    "a1b2c3d4e5f67890a1b2c3d4e5f67890",
    moq.RelayTokenRotateParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
      Type: cloudflare.F(moq.RelayTokenRotateParamsTypePublishSubscribe),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.Token)
}
{
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "messages": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "success": true,
  "result": {
    "token": "eyJhbGciOiJFZDI1NTE5...",
    "type": "publish_subscribe"
  }
}
Returns Examples
{
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "messages": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "success": true,
  "result": {
    "token": "eyJhbGciOiJFZDI1NTE5...",
    "type": "publish_subscribe"
  }
}