PHP Client for Cloudflare API
Client Reference

D1

D1 endpoint reference.

List

Returns a list of D1 databases.

ParamTypeRequiredDefaultDescription
accountIdstringYesAccount Identifier.
paramsarrayNo[]Query Parameters.
php
$response = $client->d1()->list('ACCOUNT_ID', []);
View this operation on the Cloudflare API Reference

Create

Create D1 Database

$client->d1()->create('ACCOUNT_ID', [
    'name' => 'my-database',
    'primary_location_hint' => 'weur',
]);
ParamTypeRequiredDefaultDescription
accountIdstringYesAccount Identifier.
valuesarrayYes`name` is required and must match `^[a-z0-9][a-z0-9-_]*$`. `primary_location_hint` (`wnam`, `enam`, `weur`, `eeur`, `apac` or `oc`) places the primary, defaulting to near the caller. `read_replication` and `jurisdiction` are optional.
php
$response = $client->d1()->create('ACCOUNT_ID', []);
View this operation on the Cloudflare API Reference

Get

Returns the specified D1 database.

ParamTypeRequiredDefaultDescription
accountIdstringYesAccount Identifier.
databaseIdstringYesDatabase Identifier.
php
$response = $client->d1()->get('ACCOUNT_ID', 'DATABASE_ID');
View this operation on the Cloudflare API Reference

Delete

Deletes the specified D1 database.

ParamTypeRequiredDefaultDescription
accountIdstringYesAccount Identifier.
databaseIdstringYesDatabase Identifier.
php
$response = $client->d1()->delete('ACCOUNT_ID', 'DATABASE_ID');
View this operation on the Cloudflare API Reference

Update

Updates the specified D1 database, overwriting the full configuration.

$client->d1()->update('ACCOUNT_ID', 'DATABASE_ID', [
    'read_replication' => ['mode' => 'auto'],
]);
ParamTypeRequiredDefaultDescription
accountIdstringYesAccount Identifier.
databaseIdstringYesDatabase Identifier.
valuesarrayYes`read_replication` is required, itself carrying a `mode` of `auto` to let D1 place replicas around the world, or `disabled` to use none.
php
$response = $client->d1()->update('ACCOUNT_ID', 'DATABASE_ID', []);
View this operation on the Cloudflare API Reference

Edit

Applies changes to the specified D1 database, overwriting only the supplied properties.

ParamTypeRequiredDefaultDescription
accountIdstringYesAccount Identifier.
databaseIdstringYesDatabase Identifier.
valuesarrayYesValues to patch on the database, e.g. `read_replication`.
php
$response = $client->d1()->edit('ACCOUNT_ID', 'DATABASE_ID', []);
View this operation on the Cloudflare API Reference

Bookmark

Get a Time Travel bookmark for a D1 database.

Without a timestamp you get the current bookmark; with one, the nearest bookmark at or before it. Feed either into restore().

ParamTypeRequiredDefaultDescription
accountIdstringYesAccount Identifier.
databaseIdstringYesDatabase Identifier.
timestampstring|nullNoISO 8601 timestamp to find the nearest bookmark at or before. Omit for the current bookmark.
php
$response = $client->d1()->bookmark('ACCOUNT_ID', 'DATABASE_ID', 'TIMESTAMP');
View this operation on the Cloudflare API Reference

Restore

Restore a D1 database to a previous point in time.

Give it exactly one of a bookmark or a timestamp — a bookmark from bookmark() names an exact point, a timestamp asks D1 to find the nearest one.

$bookmark = $client->d1()->bookmark('ACCOUNT_ID', 'DATABASE_ID')->json('result.bookmark');

$client->d1()->restore('ACCOUNT_ID', 'DATABASE_ID', bookmark: $bookmark);
ParamTypeRequiredDefaultDescription
accountIdstringYesAccount Identifier.
databaseIdstringYesDatabase Identifier.
bookmarkstring|nullNoBookmark to restore to. Required if `$timestamp` is not given.
timestampstring|nullNoISO 8601 timestamp to restore to. Required if `$bookmark` is not given.
php
$response = $client->d1()->restore('ACCOUNT_ID', 'DATABASE_ID', 'BOOKMARK', 'TIMESTAMP');
View this operation on the Cloudflare API Reference

Export

Returns a URL where the SQL contents of your D1 can be downloaded. Note: this process may take some time for larger DBs, during which your D1 will be unavailable to serve queries. To avoid blocking your DB unnecessarily, an in-progress export must be continually polled or will automatically cancel.

ParamTypeRequiredDefaultDescription
accountIdstringYesAccount Identifier.
databaseIdstringYesDatabase Identifier.
currentBookmarkstring|nullNoTo poll an in-progress export, provide the current bookmark (returned by your first polling response)
noDataboolNofalseExport only the table definitions, not their contents
noSchemaboolNofalseExport only each table's contents, not its definition
tablesarrayNo[]Filter the export to just one or more tables. Passing an empty array is the same as not passing anything and means: export all tables.
php
$response = $client->d1()->export('ACCOUNT_ID', 'DATABASE_ID', 'CURRENT_BOOKMARK', true, true, []);
View this operation on the Cloudflare API Reference

Import

Generates a temporary URL for uploading an SQL file to, then instructing the D1 to import it and polling it for status updates. Imports block the D1 for their duration.

ParamTypeRequiredDefaultDescription
accountIdstringYesAccount Identifier.
databaseIdstringYesDatabase Identifier.
actionstringNo'init'- `init`: Indicates you have a new SQL file to upload. - `ingest`: Indicates you've finished uploading to tell the D1 to start consuming it - `poll`: Indicates you've finished uploading to tell the D1 to start consuming it
etagstring|nullNoRequired when action is `init` or `ingest`. An md5 hash of the file you're uploading. Used to check if it already exists, and validate its contents before ingesting.
filenamestring|nullNoThe filename you have successfully uploaded.
currentBookmarkstring|nullNoThis identifies the currently-running import, checking its status.
php
$response = $client->d1()->import('ACCOUNT_ID', 'DATABASE_ID', 'ACTION', 'ETAG', 'FILENAME', 'CURRENT_BOOKMARK');
View this operation on the Cloudflare API Reference

Query

Returns the query result as an object.

ParamTypeRequiredDefaultDescription
accountIdstringYesAccount Identifier.
databaseIdstringYesDatabase Identifier.
querystringYesYour SQL query. Supports multiple statements, joined by semicolons, which will be executed as a batch.
paramsarrayNo[]Query params.
php
$response = $client->d1()->query('ACCOUNT_ID', 'DATABASE_ID', 'QUERY', []);
View this operation on the Cloudflare API Reference

Raw

Returns the query result rows as arrays rather than objects. This is a performance-optimized version of the /query endpoint.

ParamTypeRequiredDefaultDescription
accountIdstringYesAccount Identifier.
databaseIdstringYesDatabase Identifier.
querystringYesYour SQL query. Supports multiple statements, joined by semicolons, which will be executed as a batch.
paramsarrayNo[]Query params.
php
$response = $client->d1()->raw('ACCOUNT_ID', 'DATABASE_ID', 'QUERY', []);
View this operation on the Cloudflare API Reference
Copyright © 2026