Skip to content
Cloudflare Docs

API request

The APIRequest component is used 503 times on 212 pages.

See all examples of pages that use APIRequest

Used 503 times.

Pages

Partials

Import

import { APIRequest } from "~/components";

Usage

Required API token permissions

At least one of the following token permissions is required:
  • Domain API Gateway
Update zone level schema validation settings
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/api_gateway/settings/schema_validation" \
--request PUT \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"validation_default_mitigation_action": "block"
}'

Required API token permissions

At least one of the following token permissions is required:
  • SSL and Certificates Write
Delete TLS setting for hostname
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/hostnames/settings/ciphers/$HOSTNAME" \
--request DELETE \
--header "X-Auth-Email: $CLOUDFLARE_EMAIL" \
--header "X-Auth-Key: $CLOUDFLARE_API_KEY"

Required API token permissions

At least one of the following token permissions is required:
  • Images Write
Create authenticated direct upload URL V2
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/images/v2/direct_upload" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--form "requireSignedURLs=true" \
--form "metadata={\"key\":\"value\"}"

Required API token permissions

At least one of the following token permissions is required:
  • Cloud Connector Write
Put Rules
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/cloud_connector/rules" \
--request PUT \
--header "X-Auth-Email: $CLOUDFLARE_EMAIL" \
--header "X-Auth-Key: $CLOUDFLARE_API_KEY" \
--json '[
{
"expression": "http.request.uri.path wildcard \"/images/*\"",
"provider": "cloudflare_r2",
"description": "Connect to R2 bucket containing images",
"parameters": {
"host": "mybucketcustomdomain.example.com"
}
}
]'

Required API token permissions

At least one of the following token permissions is required:
  • Page Shield
  • Domain Page Shield Read
  • Domain Page Shield
  • Page Shield Read
  • Zone Settings Write
  • Zone Settings Read
List Page Shield scripts
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/page_shield/scripts?direction=asc" \
--request GET \
--header "X-Auth-Email: $CLOUDFLARE_EMAIL" \
--header "X-Auth-Key: $CLOUDFLARE_API_KEY"
import { APIRequest } from "~/components";
<APIRequest
path="/zones/{zone_id}/api_gateway/settings/schema_validation"
method="PUT"
json={{
validation_default_mitigation_action: "block",
}}
code={{
mark: [5, "block"],
}}
roles="Domain"
/>
<APIRequest
path="/zones/{zone_id}/hostnames/settings/{setting_id}/{hostname}"
method="DELETE"
parameters={{
setting_id: "ciphers",
}}
/>
<APIRequest
path="/accounts/{account_id}/images/v2/direct_upload"
method="POST"
form={{
requireSignedURLs: true,
metadata: '{"key":"value"}',
}}
/>
<APIRequest
path="/zones/{zone_id}/cloud_connector/rules"
method="PUT"
json={[
{
expression: 'http.request.uri.path wildcard "/images/*"',
provider: "cloudflare_r2",
description: "Connect to R2 bucket containing images",
parameters: {
host: "mybucketcustomdomain.example.com",
},
},
]}
/>
<APIRequest
path="/zones/{zone_id}/page_shield/scripts"
method="GET"
parameters={{
direction: "asc",
}}
/>

<APIRequest> Props

path

required

type: string

The path for the API endpoint.

This can be found in our API documentation, under the name of the endpoint.

method

required

type: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD"

The HTTP method to use.

parameters

type: Record<string, any>

The parameters to substitute - either in the URL path or as query parameters.

For example, /zones/{zone_id}/page_shield/scripts can be transformed into /zones/123/page_shield/scripts?direction=asc with the following:

parameters={{
zone_id: "123",
direction: "asc"
}}

If not provided, the component will default to an environment variable. For example, {setting_id} will be replaced with $SETTING_ID.

json

type: Record<string, any> | Record<string, any>[]

The JSON payload to send.

If required properties are missing, the component will throw an error.

Functionally, the --json option is equivalent to the --data option in cURL, but handles a few additional headers automatically.

form

type: Record<string, any>

The FormData payload to send.

This field is not currently validated against the schema.

code

type: object

An object of Expressive Code props, the following props are available:

roles

type: string | boolean

default: true

If set to true, which is the default, all API token roles will show.

If set to false, API token roles will not be displayed.

If set to a string, the API token roles will be filtered using it as a substring (i.e, roles="domain" to filter out Account API Gateway and only leave Domain API Gateway).