API Reference

Complete reference for the SparkDB Buckets API. All endpoints, request formats, response types, and error codes.

Base URLs

Client API:  https://api.sparkdb.pro/api/buckets
Developer API: https://api.sparkdb.pro/api/v1/buckets

Authentication

APIMethod
Client APISession cookie / JWT (from dashboard login)
Developer APIx-api-key: spk_your_api_key or Authorization: Bearer spk_your_api_key

Endpoints

Create Bucket

curl
POST /api/v1/buckets
Content-Type: application/json
x-api-key: spk_your_api_key

{
  "name": "my-assets",
  "visibility": "public"
}

Request Body

FieldTypeDefaultDescription
namestringrequiredBucket name, 3–40 chars, ^[a-z0-9][a-z0-9_-]{1,38}[a-z0-9]$
visibilitystring"private""public" or "private"
publicbooleanfalseAlternative to visibility

Response 201

{
  "data": {
    "id": 1,
    "name": "my-assets",
    "public": true,
    "object_count": 0,
    "total_bytes": 0,
    "created_at": "2025-06-15T10:30:00Z"
  }
}

List Buckets

curl
GET /api/v1/buckets
x-api-key: spk_your_api_key

Response 200

{
  "data": [
    {
      "id": 1,
      "name": "my-assets",
      "public": true,
      "object_count": 15,
      "total_bytes": 2457600,
      "created_at": "2025-06-15T10:30:00Z"
    }
  ],
  "buckets": [
    // Same as data (redundant keys)
  ]
}

Get Bucket

curl
GET /api/v1/buckets/1
x-api-key: spk_your_api_key

Response 200

{
  "data": {
    "id": 1,
    "name": "my-assets",
    "public": false,
    "object_count": 42,
    "total_bytes": 5242880,
    "created_at": "2025-06-15T10:30:00Z"
  }
}

Response 404

{
  "error": "Bucket not found"
}

Delete Bucket

curl
DELETE /api/v1/buckets/1
x-api-key: spk_your_api_key
Deletes all S3 objects, then soft-deletes the bucket record.

Response 200

{
  "message": "Bucket deleted successfully"
}

Update Visibility

curl
POST /api/v1/buckets/1/visibility
Content-Type: application/json
x-api-key: spk_your_api_key

{
  "visibility": "public"
}

Request Body

FieldTypeDescription
visibilitystring"public" or "private"

Response 200

{
  "message": "Visibility updated"
}

List Files

curl
GET /api/v1/buckets/1/files
x-api-key: spk_your_api_key

Response 200

{
  "data": [
    {
      "id": "1/avatar.png",
      "bucket_id": 1,
      "storage_name": "avatar.png",
      "filename": "avatar.png",
      "size": 245760,
      "content_type": "image/png",
      "url": "https://bucket.sparkdb.pro/spark-42-my-assets-a1b2/avatar.png",
      "created_at": "2025-06-15T10:30:00Z"
    }
  ],
  "objects": [
    // Same as data (redundant keys)
  ]
}

Upload File

curl
POST /api/v1/buckets/1/files
Content-Type: multipart/form-data
x-api-key: spk_your_api_key

file: @avatar.png

Response 201

{
  "data": {
    "filename": "avatar.png",
    "size": 245760,
    "updated": true
  }
}

Response 409

{
  "error": "Storage limit exceeded. Your plan allows up to 1GB of storage."
}

Upload File (Raw Body)

curl
PUT /api/v1/buckets/1/files/avatar.png
Content-Type: image/png
x-api-key: spk_your_api_key

<binary file data>
Uploads the raw request body as the file content. The Content-Type header sets the file’s MIME type. Use this for programmatic uploads where multipart form data is not convenient.

Download File

curl
GET /api/v1/buckets/1/files/avatar.png
x-api-key: spk_your_api_key    # Required for private buckets, optional for public
Returns the raw file with the correct Content-Type and Content-Length headers.

Get File Metadata

curl
HEAD /api/v1/buckets/1/files/avatar.png
x-api-key: spk_your_api_key
Returns response headers with Content-Type, Content-Length, ETag, and Last-Modified. No response body.

Delete File

curl
DELETE /api/v1/buckets/1/files/avatar.png
x-api-key: spk_your_api_key

Response 200

{
  "message": "File deleted successfully"
}

Client API Endpoints

The client API (session-based) mirrors the developer API but under /api/buckets:
MethodPathDescription
GET/api/bucketsList buckets
POST/api/bucketsCreate bucket
GET/api/buckets/:idGet bucket
DELETE/api/buckets/:idDelete bucket
POST / PATCH/api/buckets/:id/visibilityUpdate visibility
GET/api/buckets/:id/filesList files
GET/api/buckets/:id/objectsList files (alias)
POST/api/buckets/:id/filesUpload file (multipart)
POST/api/buckets/:id/uploadUpload file (alias)
PUT/api/buckets/:id/files/:filenameUpload file (raw body)
HEAD/api/buckets/:id/files/:filenameGet file metadata
GET/api/buckets/:id/files/:filenameDownload file
DELETE/api/buckets/:id/files/:filenameDelete file

Developer API Endpoints

The developer API also supports these additional aliases under /api/v1/buckets:
MethodPathDescription
GET/api/v1/buckets/listList buckets (alias)
POST/api/v1/buckets/createCreate bucket (alias)
DELETE/api/v1/buckets/:id/deleteDelete bucket (alias)
DELETE/api/v1/buckets/:id/files/:filename/deleteDelete file (alias)

Object Reference

StorageBucket

{
  "id": 1,
  "name": "my-assets",
  "public": true,
  "object_count": 42,
  "total_bytes": 5242880,
  "created_at": "2025-06-15T10:30:00Z"
}
FieldTypeDescription
idnumberUnique bucket identifier
namestringHuman-readable bucket name
publicbooleanWhether files are publicly accessible
object_countnumberNumber of files in the bucket
total_bytesnumberTotal storage used by the bucket
created_atstringISO 8601 timestamp

BucketObject

{
  "id": "1/avatar.png",
  "bucket_id": 1,
  "storage_name": "avatar.png",
  "filename": "avatar.png",
  "size": 245760,
  "content_type": "image/png",
  "url": "https://bucket.sparkdb.pro/spark-42-my-assets-a1b2/avatar.png",
  "created_at": "2025-06-15T10:30:00Z"
}
FieldTypeDescription
idstringObject identifier ({bucketId}/{filename})
bucket_idnumberParent bucket ID
storage_namestringS3 key name
filenamestringOriginal filename
sizenumberFile size in bytes
content_typestringMIME type
urlstringDownload URL
created_atstringISO 8601 timestamp

Error Codes

CodeHTTP StatusDescription
BucketNotFoundError404Bucket doesn’t exist or was soft-deleted
StorageLimitExceededError409Upload exceeds plan storage limit. Error message includes plan limit.
Validation error400Invalid bucket name, missing fields
Unauthorized401Missing or invalid API key