Cloudflare API Request
Calls any endpoint of the Cloudflare API as your connected account: Workers, R2, rules, Zero Trust, zone settings and more.
- Price per call
- 1 credit
- per successful call
- Price ceiling
- 1 credit
- every call, same price
- Failed calls
- Free
- retried automatically
- Billed
- Per call
- only on success
Endpoint
api.primaryapi.com/ v1/ run/ cloudflare. api_requestAuth: API key with run or full access, or a dashboard session
Send the input below as a JSON body. The call is routed to a healthy upstream; if an attempt fails, it is retried automatically inside the same request and you pay only for the answer you get. To check an input and see the exact price without running anything, call POST /v1/quote/cloudflare.api_request with the same body (free).
Example request
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"}}'const res = await fetch('https://api.primaryapi.com/v1/run/cloudflare.api_request', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PRIMARYAPI_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
method: 'GET',
path: '/zones',
query: {
name: 'example.com',
},
}),
});
const body = await res.json();
if (!res.ok) throw new Error(`${body.code}: ${body.error}`);
// found:false is a successful answer ("does not exist"), not an error
console.log(body.output.found ? body.output.data : body.output.reason, body.credits);import os
import requests
res = requests.post(
"https://api.primaryapi.com/v1/run/cloudflare.api_request",
headers={"Authorization": f"Bearer {os.environ['PRIMARYAPI_API_KEY']}"},
json={
"method": "GET",
"path": "/zones",
"query": {
"name": "example.com",
},
},
timeout=60,
)
body = res.json()
if not res.ok:
raise RuntimeError(f"{body['code']}: {body['error']}")
# found=False is a successful answer ("does not exist"), not an error
print(body["output"]["data"] if body["output"]["found"] else body["output"]["reason"], body["credits"]){
"name": "run_api",
"arguments": {
"sku": "cloudflare.api_request",
"input": {
"method": "GET",
"path": "/zones",
"query": {
"name": "example.com"
}
}
}
}Price this exact input first (free)
curl -sS -X POST "https://api.primaryapi.com/v1/quote/cloudflare.api_request" \
-H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"method":"GET","path":"/zones","query":{"name":"example.com"}}'Returns credits (what the call is expected to cost) and maxCredits (the most it can cost, which is set aside while it runs). Invalid input fails here the same way it would on run.
Input
JSON body fields. Unknown fields are rejected with 400 invalid_input (never silently ignored). You may add the routing controls preferLatencyUnderMs and maxCredits to the same object.
methodenumrequired- HTTP method: GET, POST, PUT, PATCH or DELETE.one of: GET, POST, PUT, PATCH, DELETE
pathstringrequired- 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.max 2048 chars
queryobject- Query parameters as name: value strings, for example { "name": "example.com", "per_page": "50" }.
bodyobject | any[]- The JSON body for POST, PUT, PATCH or DELETE, as the Cloudflare API reference describes it. Not for GET.
connectionstring- 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.max 200 chars
Output
When output.found is true, output.data has these fields.
statusinteger- Cloudflare’s HTTP status
successboolean | null- Cloudflare’s `success` (null when the answer is not its JSON envelope)
resultany- Cloudflare’s `result`, as returned
result_infoobject | null- Paging details (page, per_page, count, total_count, total_pages, cursor), when Cloudflare sends them
errorsobject[]- Cloudflare’s `errors` ({ code, message }), as returned
messagesobject[]- Cloudflare’s `messages`, as returned
textstring | null- The body as text when it is not JSON (for example a BIND zone file export), up to 200,000 characters
TypeScript type
/** output.data when output.found is true */
type CloudflareApiRequest = {
/** Cloudflare’s HTTP status */
status: number;
/** Cloudflare’s `success` (null when the answer is not its JSON envelope) */
success: boolean | null;
/** Cloudflare’s `result`, as returned */
result: unknown;
/** Paging details (page, per_page, count, total_count, total_pages, cursor), when Cloudflare sends them */
result_info: Record<string, unknown> | null;
/** Cloudflare’s `errors` ({ code, message }), as returned */
errors: Array<Record<string, unknown>>;
/** Cloudflare’s `messages`, as returned */
messages: Array<Record<string, unknown>>;
/** The body as text when it is not JSON (for example a BIND zone file export), up to 200,000 characters */
text: string | null;
};If what you asked about does not exist, is private, or a search matches nothing, the call still succeeds: output.found is false, output.data is null and output.reason says why. Such misses are free unless the notes below say misses are billed, in which case a miss costs the price of one call.
Example response
Values are placeholders that follow the output schema (strings as "string", numbers as 0); credits shows what this call would cost at the usual price.
{
"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
Calls go only to upstreams that are healthy right now. If an attempt fails, the call is retried automatically inside the same request; a failed attempt costs nothing, and a call never costs more than its quote’s maxCredits. Live figures below are measured on real traffic.
Success rate, uptime, latency and call counts are measured live from real traffic over 30 days and show “—” until there is data.
Errors
Errors are JSON { code, error, requestId } and are never charged. The ones to handle for this endpoint:
- invalid_inputThe request failed validation before anything ran.
- unauthorizedNo valid API key or session was presented.
- insufficient_balanceThe balance cannot cover the most this call could cost.
- key_limit_reachedThe key’s own spend limit is used up for the current window.
- trial_cap_reachedAn agent trial key has used its whole trial budget.
- forbiddenThe credential is valid but may not do this.
- not_foundThe thing addressed by the URL does not exist for you.
- idempotency_conflictThe
Idempotency-Keyis already bound to a different request. - rate_limitedToo many requests in the current window.
- all_sources_failedThe call could not be answered, even after automatic retries.
- service_unavailableThis API cannot run in this deployment right now.
- timeoutThe request passed its deadline before it finished.
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.
More Cloudflare endpoints
Generated from the PrimaryAPI catalog. Machine-readable contract: GET https://api.primaryapi.com/v1/apis/cloudflare.api_request.