Cloudflare
管理 DNS、CDN、Workers 等服务;附官方 OpenAPI 3.0 规范文档
- 认证方式
- API Key
- HTTPS
- Yes
- CORS
- No
- 分类
- 开发
简介
Cloudflare API 管理 Cloudflare 上的一切——DNS 区域、CDN/缓存、Workers、Pages、KV、Durable Objects、R2 存储、WAF 规则、分析等。认证是 Global API Key 或(推荐)API Tokens——没有匿名访问。
快速开始
需要 API 令牌(在 dash.cloudflare.com/profile/api-tokens 创建):
# 列出区域:
curl "https://api.cloudflare.com/client/v4/zones" \
-H "Authorization: Bearer YOUR_TOKEN"
创建 DNS 记录:
curl -X POST "https://api.cloudflare.com/client/v4/zones/ZONE_ID/dns_records" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"type": "A", "name": "example.com", "content": "192.0.2.1", "ttl": 3600}'
清空缓存:
curl -X POST "https://api.cloudflare.com/client/v4/zones/ZONE_ID/purge_cache" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"purge_everything": true}'
认证方式
- API Tokens(推荐):在 dash.cloudflare.com/profile/api-tokens 创建限定 scope 的令牌(如 “Zone.DNS:Edit”)。
- Global API Key(旧版):账号级、权限很大——推荐用令牌。
- 通过
Authorization: Bearer TOKEN发送(global key 用X-Auth-Email+X-Auth-Key)。
速率限制与注意事项
- 所有响应包装在
{"success": true, "result": ...}里——检查success和errors[]。 - 按端点限流(见文档);Workers/Pages 有自己的限额。
- API 带版本(
/client/v4/);账号级调用用/accounts/{account_id}/。 - GraphQL 分析 API 在
/graphql。
常见问题
Cloudflare API 免费吗? 是的——API 本身免费;费用来自你使用的付费功能。
用令牌还是 global key? 推荐限定 scope 的 API 令牌;global key 是权限过大的旧凭证。
如何找到 zone ID?
在控制台的域名概览里,或用你的令牌 GET /zones。
开发 分类更多
| API | Auth | HTTPS | CORS | |
|---|---|---|---|---|
| 24 Pull Requests Project to promote open source collaboration during December | No auth | Yes | Yes | ↗ |
| Agify.io Estimates the age from a first name | No auth | Yes | Yes | ↗ |
| Amazonscraperapi Amazon product, search & batch scraping API with residential proxies (1000 free) | API Key | Yes | No | ↗ |
| AmberOne Turn any website into a build-ready Android, iOS, PWA or Electron app project | API Key | Yes | No | ↗ |
| API Grátis Multiples services and public APIs | No auth | Yes | Unknown | ↗ |