Skip to main content
The Collections service allows you to create, read, update, and delete collections.

Overview

import { SnackBaseClient } from "@snackbase/sdk";

const client = new SnackBaseClient({
  baseUrl: "https://api.example.com",
});

// Access the collections service
const collections = client.collections;

List Collections

const result = await client.collections.list();

Get a Collection

const collection = await client.collections.get("collection-id");

Get Collection Names

const names = await client.collections.getNames();

Create a Collection

const collection = await client.collections.create({
  name: "posts",
  description: "Blog posts and articles",
  fields: [
    {
      name: "title",
      type: "text",
      required: true,
    },
    {
      name: "content",
      type: "text",
      required: false,
    },
  ],
});
To update the fields of a collection, you typically need to create a migration. See the Migrations service for more details.

Update a Collection

const updated = await client.collections.update("collection-id", {
  description: "Updated description",
});

Delete a Collection

await client.collections.delete("collection-id");
Deleting a collection permanently deletes all records within it. This action cannot be undone.

Export Collections

Export collections to JSON format for backup or migration:
// Export all collections
const exportData = await client.collections.export();
// exportData contains: { collections: Collection[], rules: CollectionRule[] }
You can also export specific collections:
// Export specific collections by ID
const exportData = await client.collections.export({
  collection_ids: ['col-123', 'col-456']
});
Exporting collections requires superadmin authentication. The export includes collection schemas and rules, but not the actual records.

Import Collections

Import collections from a previous export:
// Import with error strategy (fail on conflicts)
const result = await client.collections.import({
  data: exportData,
  strategy: 'error'
});
The strategy parameter determines how conflicts are handled:
  • error - Fail if a collection already exists (default)
  • skip - Skip existing collections, only import new ones
  • update - Update existing collections with the schema from the import
// Import with skip strategy
const result = await client.collections.import({
  data: exportData,
  strategy: 'skip'
});

// Import with update strategy
const result = await client.collections.import({
  data: exportData,
  strategy: 'update'
});
Importing collections requires superadmin authentication. The import result includes per-collection status and migration IDs for tracking.

Field Types

TypeDescription
textSingle-line text
numberNumeric value
booleanTrue/false value
dateDate/time value
selectSingle choice from options
jsonJSON object

Next Steps