Files
mesh-configs/skills/devops/web-hosting-deployment/references/cloudflare-api.md
T

81 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Cloudflare API Quick Reference
## Authentifizierung
```
Header: Authorization: Bearer <API_TOKEN>
Header: Content-Type: application/json
```
## API-Endpunkte
| Operation | Methode | URL |
|-----------|---------|-----|
| Zonen auflisten | GET | `/client/v4/zones` |
| Zone anlegen | POST | `/client/v4/zones` |
| Zone löschen | DELETE | `/client/v4/zones/:zone_id` |
| DNS-Records abrufen | GET | `/client/v4/zones/:zone_id/dns_records` |
| DNS-Record anlegen | POST | `/client/v4/zones/:zone_id/dns_records` |
| DNS-Record ändern | PATCH | `/client/v4/zones/:zone_id/dns_records/:record_id` |
| DNS-Record löschen | DELETE | `/client/v4/zones/:zone_id/dns_records/:record_id` |
## Zone anlegen (Minimal-Body)
```json
{
"name": "example.de",
"account": {"id": "ACCOUNT_ID"},
"jump_start": false,
"type": "full"
}
```
**Wichtig:** `jump_start: true` scannt bestehende DNS-Einträge, kann aber unerwünschte Records importieren. `false` startet mit leerer Zone.
## DNS-Record anlegen (Minimal-Body)
```json
{
"type": "A",
"name": "example.de",
"content": "92.60.38.175",
"proxied": false,
"ttl": 1
}
```
- `name: "@"` für Root-Domain, `name: "www"` für Subdomain
- `proxied: false` = graue Wolke (DNS-only), `true` = orangene Wolke (Proxy)
- `ttl: 1` = Auto-TTL
## MX-Record (Besonderheit)
```json
{
"type": "MX",
"name": "example.de",
"content": "mail.example.de",
"priority": 10,
"proxied": false,
"ttl": 1
}
```
- `priority`: Zahl (10 = Standard), niedriger = höhere Priorität
- **proxied MUSS false sein** – Cloudflare kann MX nicht proxien!
## Antwort parsen (python3 one-liner)
```bash
curl ... | python3 -c "
import json, sys
data = json.load(sys.stdin)
if data['success']:
for r in data['result']:
print(f\"{r['name']} → {r['content']}\")
else:
for e in data['errors']:
print(f\"ERROR: {e['message']}\")
"
```
## Typische Fehler
| Fehler | Ursache | Lösung |
|--------|---------|--------|
| `Invalid API Token` | Token falsch/abgelaufen | Neuen Token erstellen |
| `Zone already exists` | Zone bereits angelegt | Statt POST → GET + PATCH |
| `Invalid proxied mode for MX` | `proxied:true` bei MX | MX MUSS `proxied:false` sein |
| `Could not route to ...` | Zone-ID falsch | `GET /zones` für korrekte ID |