# Create a Cloudflare DNS Record (`cloudflare.create_dns_record`)

Adds a DNS record (A, AAAA, CNAME, MX, TXT, NS, CAA or SRV) to one of your Cloudflare zones.

Docs: https://primaryapi.com/docs/api-reference/cloudflare/create_dns_record

- Endpoint: `POST https://api.primaryapi.com/v1/run/cloudflare.create_dns_record`
- Category: Web Scraping · Platform: `cloudflare` · Kind: lookup · Status: live
- Price: 1 credit per call. Every call costs the same, including calls that were retried automatically.
- Billing unit: per successful call
- Reliability: routed to a healthy upstream and retried automatically when an attempt fails; live 30-day status: `GET https://api.primaryapi.com/v1/status/apis?sku=cloudflare.create_dns_record`
- Execution: synchronous (answers 202 only if it outlives the wait window)

## Input

| Field | Type | Required | Default | Constraints | Description |
|---|---|---|---|---|---|
| `zone` | string | yes |  | max 253 chars | The zone (domain) on Cloudflare: its domain name, for example "example.com", or its 32-character zone id from cloudflare.zones. |
| `type` | enum | yes |  | one of: A, AAAA, CNAME, MX, TXT, NS, CAA, SRV | Record type: A, AAAA, CNAME, MX, TXT, NS, CAA or SRV. |
| `name` | string | yes |  | max 255 chars | Record name: "@" for the zone apex, a single label such as "www" or "_dmarc" (placed inside the zone), or the full name ending in the zone, for example "www.example.com". Wildcards: "*.example.com". Punycode for non-ASCII names. |
| `content` | string | no |  | max 4000 chars | The value. A: an IPv4 address. AAAA: an IPv6 address. CNAME: the target host name. MX: the mail server host name. NS: the name server. TXT: the text (Cloudflare adds the quotes). Not used for CAA and SRV (use `data`). |
| `priority` | integer | no |  | 0–65535 | MX only: the preference, 0-65535 (lower is preferred). |
| `data` | object | no |  |  | CAA and SRV records only: their parts. CAA: flags, tag, value. SRV: priority, weight, port, target (the record name must start with _service._protocol, for example "_sip._tcp.example.com"). |
| `data.flags` | integer | no |  | 0–255 | CAA: flags, 0-255 (usually 0). |
| `data.tag` | string | no |  | max 15 chars | CAA: the property, for example issue, issuewild or iodef. |
| `data.value` | string | no |  | max 1000 chars | CAA: the value, for example letsencrypt.org. |
| `data.priority` | integer | no |  | 0–65535 | SRV: priority, 0-65535. |
| `data.weight` | integer | no |  | 0–65535 | SRV: weight, 0-65535. |
| `data.port` | integer | no |  | 0–65535 | SRV: port, 0-65535. |
| `data.target` | string | no |  | max 253 chars | SRV: the target host name. |
| `ttl` | 1 \| integer | no | 1 |  | Time to live in seconds: 1 = automatic (300 seconds), or 60-86400 (Enterprise zones may go down to 30). Proxied records always use 1. Default 1. |
| `proxied` | boolean | no | false |  | Send the traffic through Cloudflare (orange cloud). Only A, AAAA and CNAME records can be proxied; their TTL is then automatic. Default false (DNS only). |
| `comment` | string | no |  | max 500 chars | Your note on the record (not served in DNS). Up to 100 characters on the Free plan, 500 on other plans; no line breaks. |
| `tags` | string[] | no |  | max 20 items; items pattern: ^[A-Za-z0-9_-]{1,32}:[^\r\n]{0,100}$ | Tags as name:value, for example "team:web" (not served in DNS). Not available on the Free plan; up to 20 per record. |
| `connection` | string | no |  | max 200 chars | Which connected account to use when the workspace has several for this provider: the customId you gave it (exact), its connection id ("con_…"), its handle (login, email or @handle) or its name. Optional; prefer the customId or id, which never match two accounts. |

Unknown fields are rejected with `400 invalid_input`. The routing controls `preferLatencyUnderMs` and `maxCredits` may be sent in the same JSON body.

## Output

When `output.found` is `true`, `output.data` has this shape:

| Field | Type | Description |
|---|---|---|
| `zoneId` | string | Cloudflare zone id |
| `zone` | string | The zone’s domain name |
| `record` | object | The record as Cloudflare stored it |
| `record.id` | string | DNS record id (use it to update or delete the record) |
| `record.type` | string | A, AAAA, CNAME, MX, TXT, NS, CAA, SRV … |
| `record.name` | string | Full record name, in Punycode |
| `record.content` | string \| null | The value; for CAA and SRV a formatted summary of `data` |
| `record.proxied` | boolean | Traffic goes through Cloudflare (orange cloud) |
| `record.proxiable` | boolean \| null | Whether the record can be proxied |
| `record.ttl` | integer | Seconds; 1 = automatic |
| `record.priority` | integer \| null | MX (and URI) preference |
| `record.data` | object \| null | The parts of CAA, SRV and other structured records |
| `record.comment` | string \| null |  |
| `record.tags` | string[] |  |
| `record.createdAt` | string \| null |  |
| `record.modifiedAt` | string \| null |  |

When the thing you asked about does not exist (or a search matches nothing) the call still succeeds: `output.found` is `false`, `output.data` is `null` and `output.reason` says why (`not_found`, `private`, `no_results`, …). Misses are free unless the notes below say misses are billed.

## Example request

```bash
curl -sS -X POST "https://api.primaryapi.com/v1/run/cloudflare.create_dns_record" \
  -H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"zone":"example.com","type":"A","name":"api","content":"198.51.100.4","ttl":3600}'
```

## Example response

_Values are placeholders that follow the output schema; `credits` is what this call would cost at the usual price._

```json
{
  "output": {
    "found": true,
    "data": {
      "zoneId": "023e105f4ecef8ad9ca31a8372d0c353",
      "zone": "example.com",
      "record": {
        "id": "372e67954025e0ba6aaa6d586b9e0b59",
        "type": "A",
        "name": "api.example.com",
        "content": "198.51.100.4",
        "proxied": false,
        "proxiable": true,
        "ttl": 3600,
        "priority": null,
        "data": null,
        "comment": null,
        "tags": [],
        "createdAt": "2014-01-01T05:20:00.123Z",
        "modifiedAt": "2014-01-01T05:20:00.123Z"
      }
    }
  },
  "provider": "PrimaryAPI",
  "credits": 1,
  "items": 1,
  "requestId": "req_01JBXK6Y2N9V8T4R3Q2P1M0A7Z"
}
```

## Pricing and reliability

- Usual price: 1 credit per call
- Price ceiling: the usual price, even when a call is retried. A quote’s `maxCredits` is the most a given call can cost; the `maxCredits` routing control caps it per call
- Live 30-day status, success rate, uptime and latency: `GET https://api.primaryapi.com/v1/status/apis?sku=cloudflare.create_dns_record`

## Errors to handle

`invalid_input`, `unauthorized`, `insufficient_balance`, `key_limit_reached`, `trial_cap_reached`, `forbidden`, `not_found`, `idempotency_conflict`, `rate_limited`, `all_sources_failed`, `service_unavailable`, `timeout`. See https://primaryapi.com/docs/errors.

## Notes

Runs as your connected Cloudflare account and needs the "Manage DNS" permission. This changes the live configuration of your Cloudflare zone right away: there is no undo, no preview and no automatic retry. A call that times out may still have gone through, so read the current state (cloudflare.dns_records) before trying again. An Idempotency-Key does not protect it: results of private APIs are never stored, so a repeated key runs the change again. Cloudflare refuses an A or AAAA record on a name that has a CNAME (and the reverse), any record next to an NS record of the same name, and an exact duplicate; those come back as invalid input. Comments longer than 100 characters and tags need a paid plan.

