跳转到主要内容

Create and manage widgets using Cloudflare API

import { APIRequest } from "~/components"

Use the Cloudflare API for programmatic widget management and automation.

Prerequisites

Before you begin, you must have:

  • A Cloudflare API token with Account:Turnstile:Edit permissions
  • An account ID found in your Cloudflare dashboard

Create a widget via the API

<APIRequest path="/accounts/{account_id}/challenges/widgets" method="POST" json={{ domains: ["example.com"], mode: "managed", name: "My Example Turnstile Widget", }} />

Manage widgets via the API

<APIRequest path="/accounts/{account_id}/challenges/widgets/{sitekey}" method="PUT" json={{ domains: ["203.0.113.1", "cloudflare.com", "blog.example.com"], mode: "invisible", name: "blog.cloudflare.com login form", clearance_level: "interactive", }} />

<APIRequest path="/accounts/{account_id}/challenges/widgets/{sitekey}/rotate_secret" method="POST" json={{ invalidate_immediately: false, }} />