---
title: Rotate Secret for a Turnstile Widget
---

[Skip to content](#_top)

[API Reference](https://developers.cloudflare.com/api/go)

[Turnstile](https://developers.cloudflare.com/api/go/resources/turnstile)

[Widgets](https://developers.cloudflare.com/api/go/resources/turnstile/subresources/widgets)

Copy Markdown

Open in **Claude**Open in **ChatGPT**Open in **Cursor**

---

**Copy Markdown****View as Markdown**

# Rotate Secret for a Turnstile Widget

client.Turnstile.Widgets.RotateSecret(ctx, sitekey, params) (\*[Widget](<https://developers.cloudflare.com/api/go/resources/turnstile#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)>), error)

POST/accounts/{account\_id}/challenges/widgets/{sitekey}/rotate\_secret

Generates a new secret key for this widget. If `invalidate_immediately` is set to `false`, the previous secret remains valid for 2 hours.

Note that secrets cannot be rotated again during the grace period.

##### Security

<details>

<summary>API Token</summary>



The preferred authorization scheme for interacting with the Cloudflare API. <a href="https://developers.cloudflare.com/fundamentals/api/get-started/create-token/">Create a token</a>.

**Example:**<code>Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY</code>

</details>

<details>

<summary>API Email + API Key</summary>



The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

**Example:**<code>X-Auth-Email: user@example.com</code>

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

**Example:**<code>X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194</code>

</details>

##### Accepted Permissions (at least one required)

`Turnstile Sites Write``Account Settings Write`

##### ParametersExpand Collapse

sitekey string

Unique identifier for a Turnstile widget.

maxLength32

[Link to this property](<#(resource)%20turnstile.widgets%20%3E%20(method)%20rotate_secret%20%3E%20(params)%20default%20%3E%20(param)%20sitekey%20%3E%20(schema)>)

<details>

<summary>

params WidgetRotateSecretParams

</summary>

AccountID param.Field\[string]

Path param: Identifier

maxLength32

<a href="#(resource)%20turnstile.widgets%20%3E%20(method)%20rotate_secret%20%3E%20(params)%20default%20%3E%20(param)%20account_id">Link to this property</a>

InvalidateImmediately param.Field\[bool]Optional

Body param: If <code>invalidate_immediately</code> is set to <code>false</code>, the previous secret will remain valid for two hours. Otherwise, the secret is immediately invalidated, and requests using it will be rejected.

<a href="#(resource)%20turnstile.widgets%20%3E%20(method)%20rotate_secret%20%3E%20(params)%20default%20%3E%20(param)%20invalidate_immediately">Link to this property</a>

</details>

[Link to this property](<#(resource)%20turnstile.widgets%20%3E%20(method)%20rotate_secret%20%3E%20(params)%20default>)

##### ReturnsExpand Collapse

<details>

<summary>

type Widget struct{…}

A Turnstile widget’s detailed configuration

</summary>

BotFightMode bool

If bot\_fight\_mode is set to <code>true</code>, Cloudflare issues computationally expensive challenges in response to malicious bots (ENT only).

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20bot_fight_mode">Link to this property</a>

<details>

<summary>

ClearanceLevel WidgetClearanceLevel

If Turnstile is embedded on a Cloudflare site and the widget should grant challenge clearance, this setting can determine the clearance level to be set

</summary>

One of the following:

const WidgetClearanceLevelNoClearance WidgetClearanceLevel = "no\_clearance"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20clearance_level%20%3E%20(member)%200">Link to this property</a>

const WidgetClearanceLevelJschallenge WidgetClearanceLevel = "jschallenge"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20clearance_level%20%3E%20(member)%201">Link to this property</a>

const WidgetClearanceLevelManaged WidgetClearanceLevel = "managed"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20clearance_level%20%3E%20(member)%202">Link to this property</a>

const WidgetClearanceLevelInteractive WidgetClearanceLevel = "interactive"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20clearance_level%20%3E%20(member)%203">Link to this property</a>

</details>

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20clearance_level">Link to this property</a>

CreatedOn Time

When the widget was created.

formatdate-time

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20created_on">Link to this property</a>

Domains \[]<a href="https://developers.cloudflare.com/api/go/resources/turnstile#(resource)%20turnstile.widgets%20%3E%20(model)%20widget_domain%20%3E%20(schema)">WidgetDomain</a>

maxLength10

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20domains">Link to this property</a>

EphemeralID bool

Return the Ephemeral ID in /siteverify (ENT only).

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20ephemeral_id">Link to this property</a>

<details>

<summary>

Mode WidgetMode

Widget Mode

</summary>

One of the following:

const WidgetModeNonInteractive WidgetMode = "non-interactive"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20mode%20%3E%20(member)%200">Link to this property</a>

const WidgetModeInvisible WidgetMode = "invisible"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20mode%20%3E%20(member)%201">Link to this property</a>

const WidgetModeManaged WidgetMode = "managed"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20mode%20%3E%20(member)%202">Link to this property</a>

</details>

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20mode">Link to this property</a>

ModifiedOn Time

When the widget was modified.

formatdate-time

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20modified_on">Link to this property</a>

Name string

Human readable widget name. Not unique. Cloudflare suggests that you set this to a meaningful string to make it easier to identify your widget, and where it is used.

maxLength254

minLength1

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20name">Link to this property</a>

Offlabel bool

Do not show any Cloudflare branding on the widget (ENT only).

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20offlabel">Link to this property</a>

<details>

<summary>

Region WidgetRegion

Region where this widget can be used. This cannot be changed after creation.

</summary>

One of the following:

const WidgetRegionWorld WidgetRegion = "world"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20region%20%3E%20(member)%200">Link to this property</a>

const WidgetRegionChina WidgetRegion = "china"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20region%20%3E%20(member)%201">Link to this property</a>

</details>

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20region">Link to this property</a>

Secret string

Secret key for this widget.

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20secret">Link to this property</a>

Sitekey string

Unique identifier for a Turnstile widget.

maxLength32

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20sitekey">Link to this property</a>

<details>

<summary>

DeployedVia WidgetDeployedViaOptional

Origin that created this widget, recorded at creation time and immutable afterward. Server-derived from the create request; not client-settable. Omitted from the response for widgets created before this field existed.

</summary>

One of the following:

const WidgetDeployedViaWrangler WidgetDeployedVia = "wrangler"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20deployed_via%20%3E%20(member)%200">Link to this property</a>

const WidgetDeployedViaDashboard WidgetDeployedVia = "dashboard"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20deployed_via%20%3E%20(member)%201">Link to this property</a>

const WidgetDeployedViaSpin WidgetDeployedVia = "spin"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20deployed_via%20%3E%20(member)%202">Link to this property</a>

const WidgetDeployedViaAPI WidgetDeployedVia = "api"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20deployed_via%20%3E%20(member)%203">Link to this property</a>

const WidgetDeployedViaUnknown WidgetDeployedVia = "unknown"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20deployed_via%20%3E%20(member)%204">Link to this property</a>

</details>

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20deployed_via">Link to this property</a>

<details>

<summary>

LastModifiedVia WidgetLastModifiedViaOptional

Origin of the most recent mutation (create, update, delete, or secret rotation). Server-derived; not client-settable. Omitted for widgets last mutated before this field existed.

</summary>

One of the following:

const WidgetLastModifiedViaWrangler WidgetLastModifiedVia = "wrangler"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20last_modified_via%20%3E%20(member)%200">Link to this property</a>

const WidgetLastModifiedViaDashboard WidgetLastModifiedVia = "dashboard"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20last_modified_via%20%3E%20(member)%201">Link to this property</a>

const WidgetLastModifiedViaSpin WidgetLastModifiedVia = "spin"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20last_modified_via%20%3E%20(member)%202">Link to this property</a>

const WidgetLastModifiedViaAPI WidgetLastModifiedVia = "api"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20last_modified_via%20%3E%20(member)%203">Link to this property</a>

const WidgetLastModifiedViaUnknown WidgetLastModifiedVia = "unknown"

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20last_modified_via%20%3E%20(member)%204">Link to this property</a>

</details>

<a href="#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)%20%3E%20(property)%20last_modified_via">Link to this property</a>

</details>

[Link to this property](<#(resource)%20turnstile.widgets%20%3E%20(model)%20widget%20%3E%20(schema)>)

### Rotate Secret for a Turnstile Widget

Go

HTTPTypeScriptPythonGoTerraform

```
package main

import (
  "context"
  "fmt"

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

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  widget, err := client.Turnstile.Widgets.RotateSecret(
    context.TODO(),
    "0x4AAF00AAAABn0R22HWm-YUc",
    turnstile.WidgetRotateSecretParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", widget.EphemeralID)
}
```

200 example

```
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "success": true,
  "result": {
    "bot_fight_mode": false,
    "clearance_level": "interactive",
    "created_on": "2014-01-01T05:20:00.123123Z",
    "domains": [
      "203.0.113.1",
      "cloudflare.com",
      "blog.example.com"
    ],
    "ephemeral_id": false,
    "mode": "invisible",
    "modified_on": "2014-01-01T05:20:00.123123Z",
    "name": "blog.cloudflare.com login form",
    "offlabel": false,
    "region": "world",
    "secret": "0x4AAF00AAAABn0R22HWm098HVBjhdsYUc",
    "sitekey": "0x4AAF00AAAABn0R22HWm-YUc",
    "deployed_via": "wrangler",
    "last_modified_via": "dashboard"
  }
}
```

##### Returns Examples

200 example

```
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "success": true,
  "result": {
    "bot_fight_mode": false,
    "clearance_level": "interactive",
    "created_on": "2014-01-01T05:20:00.123123Z",
    "domains": [
      "203.0.113.1",
      "cloudflare.com",
      "blog.example.com"
    ],
    "ephemeral_id": false,
    "mode": "invisible",
    "modified_on": "2014-01-01T05:20:00.123123Z",
    "name": "blog.cloudflare.com login form",
    "offlabel": false,
    "region": "world",
    "secret": "0x4AAF00AAAABn0R22HWm098HVBjhdsYUc",
    "sitekey": "0x4AAF00AAAABn0R22HWm-YUc",
    "deployed_via": "wrangler",
    "last_modified_via": "dashboard"
  }
}
```