Using a plain curl to send a query provides the ability to slice-n-dice with theresults and apply post-processing if needed. For example, convertingresults received from GraphQL API into a CSV format.
For more functionality, like auto-completion, schema exploring, etc., you canlook at GraphQLclients.
GraphQL API expects JSON with two essentials fields: "query" and "variables".
A query should be stripped from newline symbols and sent as a single-line stringwhen the variables is an object full of values for all placeholders used in thequery:
{"query":"{viewer { ... }}","variables":{}}
It is still possible to use a human-friendly query though. In the example belowyou can see howecho
piped together withtr
to provide a proper payload withcurl
:
echo'{ "query":"{viewer {zones(filter: { zoneTag: $zoneTag }) {firewallEventsAdaptive(filter: $filterlimit: 10orderBy: [datetime_DESC]) {actionclientAsnclientCountryNameclientIPclientRequestPathclientRequestQuerydatetimesourceuserAgent}}}}","variables": {"zoneTag": "<zone-tag>","filter": {"datetime_geq": "2022-07-24T11:00:00Z","datetime_leq": "2022-07-24T12:00:00Z"}}}'|tr-d'\n'|curl--silent\https://api.cloudflare.com/client/v4/graphql\--header"Authorization: Bearer <API_TOKEN>"\--header"Content-Type: application/json"\--data@-
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark