API documentation
Everything you need to call the KDrive API from your own code: how to authenticate, how requests and errors look, and how files move in and out.
On this page
Overview
The KDrive API is a REST API over HTTPS. It sends and receives JSON. You use it to manage folders and files, upload and download file content, create share links, read the event feed and receive webhooks.
Programmatic access is a Pro feature. See Pricing for the plans.
- Base URL.
https://api.kdrive.io. Every path starts with/v1/. - Formats. Requests and responses use JSON. Errors use
application/problem+json.
Next steps: Quickstart, Authentication, Developers page.
Quickstart
- Step 1.
Create an API key in the web app. Open Settings, Developers, create a key, tick the scopes it needs and copy it. The key is shown once.
- Step 2.
Send your key to
GET /v1/me. The response describes your account.curl -H "Authorization: Bearer $API_KEY" https://api.kdrive.io/v1/me
If the call answers 401, check the key. If it answers 403, your plan or your key's scopes do not allow it. Both are described under Errors.
Next steps: Authentication, Uploading and downloading files.
Authentication
Send your API key as a bearer token in the Authorization header. API keys are a Pro feature. You create and revoke them in the web app, under Settings, Developers.
Authorization: Bearer <your key>Scopes
A key can do only what its scopes allow. A request that needs a scope the key lacks fails with 403.
| Scope | What it allows |
|---|---|
files:read | Read files and folders, search, and create download URLs. |
files:write | Create, change and delete files and folders, and upload content. |
shares:read | List share links. |
shares:write | Create, change and revoke share links. |
webhooks:read | List webhook endpoints and their deliveries. |
webhooks:write | Create, change and delete webhook endpoints. |
events:read | Read the event feed. |
Next steps: Errors, Manage your keys.
Requests and responses
These conventions apply to every operation. The reference lists the exact fields of each one.
- Content type. Send JSON bodies with
Content-Type: application/json. - Identifiers. Identifiers are opaque strings. Store and send them as they are.
- Timestamps. Timestamps are RFC 3339 date-times.
- Request ids. Every response carries a
Kdrive-Request-Idheader. Quote it when you ask for help.
Next steps: Errors, Pagination.
Errors
A failed request answers with a problem document ( application/problem+json) that holds status, code, detail and request_id. Branch on the code, not on the detail text.
{
"type": "about:blank",
"title": "Forbidden",
"status": 403,
"code": "plan_feature_required",
"detail": "...",
"request_id": "req_..."
}| Status | What a client does |
|---|---|
400 | The request is malformed. Read detail, fix it and send it again. |
401 | The key is missing, wrong or revoked. Send a valid key. |
403 | The key may not do this: its plan or its scopes do not allow it. Do not retry unchanged. |
404 | The resource does not exist, or you cannot see it. |
409 | The request conflicts with the current state, such as a name that is taken. Change it or resolve the conflict. |
410 | The resource or upload is gone. Start again. |
413 | The content is too large for your plan. |
422 | The request is well formed but cannot be done. Read detail. |
429 | Too many requests. Wait for Retry-After, then retry. |
5xx | A server problem. Retry with a growing delay and quote the request id if it persists. |
The reference lists every error code.
Next steps: Rate limits, Reference.
Pagination
Lists are paged with cursors. When more results exist, the response carries next_cursor. Send it back as the cursor parameter to continue, and stop when it is empty. The event feed continues with the after parameter instead. Treat cursors as opaque.
Rate limits
Limits apply to the API. When one is reached the API answers 429; wait for the number of seconds in the Retry-After header before you try again.
Uploading and downloading files
File content does not travel through the JSON calls. The API tells you where to send it.
- Step 1.
Start an upload with
createUpload. The response says how the content is to be sent and gives the URLs to use. - Step 2.
Send the content to the URLs the API returned, in the way the response describes. Follow the response; do not assume a mode.
- Step 3.
Finish with
completeUpload. If it names parts that are missing, send those and complete again. UsegetUploadto see where an upload stands andabortUploadto cancel it.
To download, ask for a download URL with createDownloadUrl and fetch the content from the URL it returns, or call downloadFileContent and follow its redirect.
Webhooks
A webhook endpoint receives an HTTPS POST with a JSON event for each change you subscribe to. You manage endpoints through the API with the webhook scopes.
Events
| Event type | Sent when |
|---|---|
file.created | A file was created. |
file.updated | A file was renamed or moved. |
file.version_created | A new version of a file was stored. |
file.trashed | A file was moved to the trash. |
file.restored | A file was restored from the trash. |
file.deleted | A file was deleted permanently. |
folder.created | A folder was created. |
folder.updated | A folder was renamed or moved. |
folder.trashed | A folder was moved to the trash. |
folder.restored | A folder was restored from the trash. |
folder.deleted | A folder was deleted permanently. |
share.created | A share link was created. |
share.updated | A share link was changed. |
share.revoked | A share link was revoked. |
share.downloaded | A file was downloaded through a share link. |
Verify a delivery
Every delivery carries three headers. Check the signature before you trust the body.
-
Kdrive-Webhook-Id: the id of the event. -
Kdrive-Webhook-Timestamp: the time the delivery was signed. -
Kdrive-Webhook-Signature: the signature, which starts withv1=.
The signature is the HMAC-SHA256 hex digest of the timestamp, a dot, the id, a dot and the raw request body, keyed with the endpoint's secret, prefixed with v1=. Compare it with the header in constant time, and reject a delivery whose timestamp is too old. Answer with a 2xx status once you have accepted the event.
Next steps: Authentication, Reference.
Reference
The reference lists every supported operation with its parameters, request bodies, responses, error codes and examples. It is generated from the API contract, so it always matches the API.
| Group | What it covers | Credential |
|---|---|---|
| auth | Sign-up, sign-in, email verification and password reset, and the list of sign-in providers. | None |
| account | Read the current account, its plan, usage and limits. | Any API key |
| billing | List the plans and their limits. | None |
| drive | Folders, files, search, the trash and batch changes. | files:read, files:write |
| uploads | Start, inspect, complete and abort uploads; create download URLs. | files:write, files:read |
| versions | List, restore and delete file versions. | files:read, files:write |
| shares | Create, update, list and revoke share links. | shares:read, shares:write |
| zips | Download several files and folders as one zip. | files:read |
| transfers | Send files without an account through an anonymous transfer. | None or transfer token |
| webhooks | Manage webhook endpoints, send a test ping, list deliveries. | webhooks:read, webhooks:write |
| events | Read the event feed. | events:read |
| public | Open and download a share link or a transfer as a visitor. | None |
Next steps: Quickstart, Errors.
Support
Email [email protected] and include the request id of the failed response. Never send an API key or a webhook secret.
For legal questions see the Terms and Privacy pages.
Next steps: Developers page, Pricing, API keys.