Search + K

Command Palette

Search for a command to run...

Sign In

Import SQL into your D1 Database

POST /accounts/{account_id}/d1/database/{database_id}/import
Copy endpoint
https://api.cloudflare.com/client/v4

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.

Parameters

path Path Parameters

Name Type
account_id required
type D1AccountIdentifier = string
database_id required
type D1DatabaseIdentifier = string

Request Body

application/json required
{ action: "init";etag: string; } | { action: "ingest";etag: string;filename: string; } | { action: "poll";current_bookmark: string; }

Responses

200 application/json

Successful action. Import is either ready to start, under way, or finished (succeeded or failed).

interface D1ApiResponseCommon {
errors: D1Messages
type D1Messages = { code: number;message: string; }[]
;
messages: D1Messages
type D1Messages = { code: number;message: string; }[]
;
result: {};
success: true;
}
& { result?: {
at_bookmark?: string;
error?: string;
filename?: string;
messages?: string[];
result?: { final_bookmark?: string;meta?: D1QueryMeta
interface D1QueryMeta {
changed_db?: boolean;
changes?: number;
duration?: number;
last_row_id?: number;
rows_read?: number;
rows_written?: number;
served_by_primary?: boolean;
served_by_region?: D1ServedByRegion;
size_after?: number;
timings?: { sql_duration_ms?: number; };
}
;num_queries?: number; }
;
status?: "complete" | "error";
success?: boolean;
type?: "import";
upload_url?: string;
}
; }
202 application/json

Polled successfully, task is currently running

interface D1ApiResponseCommon {
errors: D1Messages
type D1Messages = { code: number;message: string; }[]
;
messages: D1Messages
type D1Messages = { code: number;message: string; }[]
;
result: {};
success: true;
}
& { result?: {
at_bookmark?: string;
messages?: string[];
status?: "active";
success?: boolean;
type?: "import";
}
; }

Client Errors

4XX application/json

Poll failed (API error)

interface D1ApiResponseCommonFailure {
errors: D1Messages
type D1Messages = { code: number;message: string; }[]
;
messages: D1Messages
type D1Messages = { code: number;message: string; }[]
;
result: null;
success: false;
}