使用 Cloudflare API 进行编程式的小组件管理和自动化。
在开始之前,您必须具备:
- 具有
Account:Turnstile:Edit权限的 Cloudflare API 令牌 - 在您的 Cloudflare 仪表板中找到的账户 ID
Required API token permissions
At least one of the following token permissions is required:Turnstile Sites WriteAccount Settings Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/challenges/widgets" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"domains": [
"example.com"
],
"mode": "managed",
"name": "My Example Turnstile Widget"
}'Required API token permissions
At least one of the following token permissions is required:Turnstile Sites WriteTurnstile Sites ReadAccount Settings WriteAccount Settings Read
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/challenges/widgets" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"Required API token permissions
At least one of the following token permissions is required:Turnstile Sites WriteTurnstile Sites ReadAccount Settings WriteAccount Settings Read
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/challenges/widgets/$SITEKEY" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"Required API token permissions
At least one of the following token permissions is required:Turnstile Sites WriteAccount Settings Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/challenges/widgets/$SITEKEY" \
--request PUT \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"domains": [
"203.0.113.1",
"cloudflare.com",
"blog.example.com"
],
"mode": "invisible",
"name": "blog.cloudflare.com login form",
"clearance_level": "interactive"
}'Required API token permissions
At least one of the following token permissions is required:Turnstile Sites WriteAccount Settings Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/challenges/widgets/$SITEKEY/rotate_secret" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"invalidate_immediately": false
}'Required API token permissions
At least one of the following token permissions is required:Turnstile Sites WriteAccount Settings Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/challenges/widgets/$SITEKEY" \
--request DELETE \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"