MarkdownCopies this page as Markdown, ready to paste into an AI assistant.
Cloudflare API
7 Cloudflare endpoints behind one key, priced in credits per call and routed to the cheapest healthy source.
On this page
Web Scraping · 7 endpoints · from 1 credit per call
Endpoints
- POSTCloudflare DNS Records
/v1/run/cloudflare.dns_recordsLists the DNS records of one of your Cloudflare zones, filtered by type, name, content or proxy status.1 creditper call - POSTCloudflare Zone Analytics
/v1/run/cloudflare.zone_analyticsTraffic of one of your Cloudflare zones by day or hour: requests, bandwidth, cached vs uncached, threats and page views.1 creditper call - POSTCreate a Cloudflare DNS Record
/v1/run/cloudflare.create_dns_recordAdds a DNS record (A, AAAA, CNAME, MX, TXT, NS, CAA or SRV) to one of your Cloudflare zones.1 creditper call - POSTDelete a Cloudflare DNS Record
/v1/run/cloudflare.delete_dns_recordPermanently deletes one DNS record from one of your Cloudflare zones and returns what was deleted.1 creditper call - POSTMy Cloudflare Zones
/v1/run/cloudflare.zonesLists the zones (domains) your connected Cloudflare account can see, with status, plan and name servers.1 creditper call - POSTPurge Cloudflare Cache
/v1/run/cloudflare.purge_cacheClears cached content of one of your Cloudflare zones: everything, or by URLs, host names, cache tags or URL prefixes.1 creditper call - POSTUpdate a Cloudflare DNS Record
/v1/run/cloudflare.update_dns_recordChanges part of an existing DNS record in one of your Cloudflare zones and returns it before and after.1 creditper call
Calling them
Every endpoint on this page is one POST to https://api.primaryapi.com/v1/run/{sku} with your API key and a JSON body. Responses share one envelope, so code written for one endpoint handles the others. For example, cloudflare.dns_records:
curl -sS -X POST "https://api.primaryapi.com/v1/run/cloudflare.dns_records" \
-H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"zone":"example.com","limit":2}'const res = await fetch('https://api.primaryapi.com/v1/run/cloudflare.dns_records', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PRIMARYAPI_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
zone: 'example.com',
limit: 2,
}),
});
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.dns_records",
headers={"Authorization": f"Bearer {os.environ['PRIMARYAPI_API_KEY']}"},
json={
"zone": "example.com",
"limit": 2,
},
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"])New to PrimaryAPI? Start with the Quickstart, then read Making requests.