# Cloudflare API Request (`cloudflare.api_request`)

Calls any endpoint of the Cloudflare API as your connected account: Workers, R2, rules, Zero Trust, zone settings and more.

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

- Endpoint: `POST https://api.primaryapi.com/v1/run/cloudflare.api_request`
- 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.api_request`
- Execution: synchronous (answers 202 only if it outlives the wait window)

## Input

| Field | Type | Required | Default | Constraints | Description |
|---|---|---|---|---|---|
| `method` | enum | yes |  | one of: GET, POST, PUT, PATCH, DELETE | HTTP method: GET, POST, PUT, PATCH or DELETE. |
| `path` | string | yes |  | max 2048 chars | The endpoint, relative to https://api.cloudflare.com/client/v4, for example "/zones" or "/accounts/{account_id}/workers/scripts". Starts with "/". No host, no query string. |
| `query` | object | no |  |  | Query parameters as name: value strings, for example { "name": "example.com", "per_page": "50" }. |
| `body` | object \| any[] | no |  |  | The JSON body for POST, PUT, PATCH or DELETE, as the Cloudflare API reference describes it. Not for GET. |
| `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 |
|---|---|---|
| `status` | integer | Cloudflare’s HTTP status |
| `success` | boolean \| null | Cloudflare’s `success` (null when the answer is not its JSON envelope) |
| `result` | any | Cloudflare’s `result`, as returned |
| `result_info` | object \| null | Paging details (page, per_page, count, total_count, total_pages, cursor), when Cloudflare sends them |
| `errors` | object[] | Cloudflare’s `errors` ({ code, message }), as returned |
| `messages` | object[] | Cloudflare’s `messages`, as returned |
| `text` | string \| null | The body as text when it is not JSON (for example a BIND zone file export), up to 200,000 characters |

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.api_request" \
  -H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"method":"GET","path":"/zones","query":{"name":"example.com"}}'
```

## 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": {
      "status": 200,
      "success": true,
      "result": [
        {
          "id": "023e105f4ecef8ad9ca31a8372d0c353",
          "account": {
            "id": "01a7362d577a6c3019a474fd6f485823",
            "name": "Example Account Name"
          },
          "activated_on": "2014-01-02T00:01:00.12345Z",
          "created_on": "2014-01-01T05:20:00.12345Z",
          "development_mode": 7200,
          "meta": {
            "cdn_only": true,
            "custom_certificate_quota": 1,
            "dns_only": true,
            "foundation_dns": true,
            "page_rule_quota": 100,
            "phishing_detected": false,
            "step": 2
          },
          "modified_on": "2014-01-01T05:20:00.12345Z",
          "name": "example.com",
          "name_servers": [
            "bob.ns.cloudflare.com",
            "lola.ns.cloudflare.com"
          ],
          "original_dnshost": "NameCheap",
          "original_name_servers": [
            "ns1.originaldnshost.com",
            "ns2.originaldnshost.com"
          ],
          "original_registrar": "GoDaddy",
          "owner": {
            "id": "023e105f4ecef8ad9ca31a8372d0c353",
            "name": "Example Org",
            "type": "organization"
          },
          "paused": false,
          "plan": {
            "id": "023e105f4ecef8ad9ca31a8372d0c353",
            "can_subscribe": false,
            "currency": "USD",
            "externally_managed": false,
            "frequency": "monthly",
            "is_subscribed": false,
            "legacy_discount": false,
            "legacy_id": "free",
            "name": "Example Org",
            "price": 10.99
          },
          "status": "active",
          "type": "full",
          "vanity_name_servers": [
            "ns1.example.com",
            "ns2.example.com"
          ]
        }
      ],
      "result_info": {
        "page": 1,
        "per_page": 20,
        "count": 1,
        "total_count": 1,
        "total_pages": 1
      },
      "errors": [],
      "messages": [],
      "text": null
    }
  },
  "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.api_request`

## 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 "Everything your account allows" permission. It can read and change anything that account allows, including deleting zones, Workers and data, so confirm with the person before any call that is not a GET. Changes apply right away, with no undo and no automatic retry; a call that times out may still have gone through, so read the current state before trying again. Repeating it with the same Idempotency-Key and input returns the first call’s stored result. Prefer the dedicated Cloudflare APIs (cloudflare.zones, cloudflare.create_dns_record, cloudflare.create_zone …) when one fits. The path is relative to https://api.cloudflare.com/client/v4; requests never go to another host. Cloudflare’s answer comes back as it is (status, success, result, result_info, errors, messages), including its refusals such as a 400; a 404 is found: false (reason not_found). JSON bodies only.

