Import SQL into your D1 Database
POST
/accounts/{account_id}/d1/database/{database_id}/import 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 ;
messages:D1Messages ;
result: {};
success: true;
} & { result?: {
at_bookmark?: string;
error?: string;
filename?: string;
messages?: string[];
result?: { final_bookmark?: string;meta?:D1QueryMeta ;num_queries?: number; };
status?: "complete" | "error";
success?: boolean;
type?: "import";
upload_url?: string;
}; }
errors:
messages:
result: {};
success: true;
} & { result?: {
at_bookmark?: string;
error?: string;
filename?: string;
messages?: string[];
result?: { final_bookmark?: string;meta?:
status?: "complete" | "error";
success?: boolean;
type?: "import";
upload_url?: string;
}; }
202 application/json
Polled successfully, task is currently running
interface D1ApiResponseCommon {
errors:D1Messages ;
messages:D1Messages ;
result: {};
success: true;
} & { result?: {
at_bookmark?: string;
messages?: string[];
status?: "active";
success?: boolean;
type?: "import";
}; }
errors:
messages:
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 ;
messages:D1Messages ;
result: null;
success: false;
}
errors:
messages:
result: null;
success: false;
}