Common API calls (2)
Last updated Oct 21, 2026 The following sections contain example requests for common API calls. For a list of available API endpoints, refer to Endpoints.
List all programs
This example fetches all Programmable Flow Protection programs in the account.
Requestbash
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/magic/programmable_flow_protection/configs/programs" \
--header "Authorization: Bearer <API_TOKEN>"
Responsejson
{
"result": [
{
"id": "<PROGRAM_ID>",
"name": "rate-limiter",
"status": "success",
"version": 1,
"created_on": "<TIMESTAMP>",
"modified_on": "<TIMESTAMP>"
}
],
"success": true,
"errors": [],
"messages": []
}
Upload a program
This example uploads a new eBPF program written in C. The program source code is sent as the request body with Content-Type: text/plain.
Include the optional X-Program-Name header to specify a human-readable program name. If omitted, the API generates a UUID as the program name.
Requestbash
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/magic/programmable_flow_protection/configs/programs" \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: text/plain" \
--header "X-Program-Name: my-rate-limiter" \
--data-binary "@/path/to/program.c"
Responsejson
{
"result": {
"id": "<PROGRAM_ID>",
"name": "my-rate-limiter",
"status": "success",
"version": 1,
"created_on": "<TIMESTAMP>",
"modified_on": "<TIMESTAMP>"
},
"success": true,
"errors": [],
"messages": []
}
If the program fails compilation or verification, the API returns a detailed error message:
Example error responsejson
{
"result": null,
"success": false,
"errors": [
{
"code": 1001,
"message": "Program verification failed: invalid memory access at line 42"
}
],
"messages": []
}
Update a program
This example updates an existing program with new source code. Each update creates a new version under the same program ID. Rules using the program remain pinned to their existing program_version. If the new program fails compilation or verification, the update fails and the existing version remains active.
Requestbash
curl --request PATCH \
"https://api.cloudflare.com/client/v4/accounts/{account_id}/magic/programmable_flow_protection/configs/programs/{program_id}" \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: text/plain" \
--data-binary "@/path/to/updated-program.c"
Responsejson
{
"result": {
"id": "<PROGRAM_ID>",
"name": "program",
"status": "success",
"version": 2,
"created_on": "<TIMESTAMP>",
"modified_on": "<TIMESTAMP>"
},
"success": true,
"errors": [],
"messages": []
}
Delete a program
This example deletes a program. You cannot delete a program that is currently referenced by an active rule.
Requestbash
curl --request DELETE \
"https://api.cloudflare.com/client/v4/accounts/{account_id}/magic/programmable_flow_protection/configs/programs/{program_id}" \
--header "Authorization: Bearer <API_TOKEN>"
Responsejson
{
"result": null,
"success": true,
"errors": [],
"messages": []
}
List all rules
This example fetches all Programmable Flow Protection rules in the account.
Requestbash
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/magic/programmable_flow_protection/configs/rules" \
--header "Authorization: Bearer <API_TOKEN>"
Responsejson
{
"result": [
{
"id": "<RULE_ID>",
"program_id": "<PROGRAM_ID>",
"program_version": 1,
"scope": "global",
"name": "global",
"mode": "enabled",
"expression": "",
"created_on": "<TIMESTAMP>",
"modified_on": "<TIMESTAMP>"
}
],
"success": true,
"errors": [],
"messages": []
}
Create a rule
This example creates a Programmable Flow Protection rule with a global scope in monitoring mode.
Requestbash
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/magic/programmable_flow_protection/configs/rules" \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"program_id": "<PROGRAM_ID>",
"scope": "global",
"name": "global",
"mode": "monitoring"
}'
Responsejson
{
"result": {
"id": "<RULE_ID>",
"program_id": "<PROGRAM_ID>",
"program_version": 1,
"scope": "global",
"name": "global",
"mode": "monitoring",
"expression": "",
"created_on": "<TIMESTAMP>",
"modified_on": "<TIMESTAMP>"
},
"success": true,
"errors": [],
"messages": []
}
Refer to JSON objects for more information on the fields in the JSON body.
Create a rule with regional scope
This example creates a rule scoped to the Western Europe region with an expression filter.
Requestbash
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/magic/programmable_flow_protection/configs/rules" \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"program_id": "<PROGRAM_ID>",
"scope": "region",
"name": "WEUR",
"mode": "enabled",
"expression": "ip.dst in { 192.0.2.0/24 }"
}'
Responsejson
{
"result": {
"id": "<RULE_ID>",
"program_id": "<PROGRAM_ID>",
"program_version": 1,
"scope": "region",
"name": "WEUR",
"mode": "enabled",
"expression": "ip.dst in { 192.0.2.0/24 }",
"created_on": "<TIMESTAMP>",
"modified_on": "<TIMESTAMP>"
},
"success": true,
"errors": [],
"messages": []
}
Refer to JSON objects for more information on the fields in the JSON body.
Update a rule
This example updates an existing rule's mode and pins it to version 2 of its program. If you omit program_version, the rule remains pinned to its existing version.
Requestbash
curl --request PATCH \
"https://api.cloudflare.com/client/v4/accounts/{account_id}/magic/programmable_flow_protection/configs/rules/{rule_id}" \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"mode": "enabled",
"program_version": 2
}'
Responsejson
{
"result": {
"id": "<RULE_ID>",
"program_id": "<PROGRAM_ID>",
"program_version": 2,
"scope": "global",
"name": "global",
"mode": "enabled",
"expression": "",
"created_on": "<TIMESTAMP>",
"modified_on": "<TIMESTAMP>"
},
"success": true,
"errors": [],
"messages": []
}
Refer to JSON objects for more information on the fields in the JSON body.
Delete a rule
This example deletes an existing rule.
Requestbash
curl --request DELETE \
"https://api.cloudflare.com/client/v4/accounts/{account_id}/magic/programmable_flow_protection/configs/rules/{rule_id}" \
--header "Authorization: Bearer <API_TOKEN>"
Responsejson
{
"result": null,
"success": true,
"errors": [],
"messages": []
}
Debug a program with PCAP
This example runs a program against a PCAP file for debugging. The API returns an annotated PCAP file with the program verdict for each packet.
The request body must contain the PCAP file in binary format. The API automatically detects the IP header offset based on the input PCAP. To override automatic detection, use the optional ip_offset query parameter to specify the number of bytes the IP header is offset by in each packet (for example, 14 for Ethernet frames).
Requestbash
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/magic/programmable_flow_protection/configs/programs/{program_id}/pcap" \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/vnd.tcpdump.pcap" \
--data-binary "@/path/to/input.pcap" \
--output output.pcap
The output PCAP file contains the same packets as the input file, but with annotations on each packet. The Packet Comment annotation may contain:
- Program return value:
CF_EBPF_PASSorCF_EBPF_DROP Ignored: if the incoming packet is not UDPAnalytics tag: the custom network analytics tag set by the program on this packet, if anyChallenge packet: the challenge packet emitted from the program back to the client, if any
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/ddos-protection/advanced-ddos-systems/api/programmable-flow-protection/examples/#page","headline":"Common API calls","description":"Example API requests for managing Programmable Flow Protection programs and rules.","url":"https://developers.cloudflare.com/ddos-protection/advanced-ddos-systems/api/programmable-flow-protection/examples/","inLanguage":"en","image":"https://developers.cloudflare.com/ddos-protection/advanced-ddos-systems/api/programmable-flow-protection/examples/og.png?v=ed25b9329656ba65","dateModified":"2026-10-21","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["REST API"]}
description: JSON object structure for Programmable Flow Protection API requests and responses. title: JSON objects image: https://developers.cloudflare.com/ddos-protection/advanced-ddos-systems/api/programmable-flow-protection/json-objects/og.png?v=ac75d61b21367c40
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/ddos-protection/llms.txt
Use this file to discover all available pages before exploring further.
Docs