Backend API

Define data collections and their API behavior. There are many standard models configured by default, such as products, orders, and others. Data models can be created manually in the Swell dashboard under Developer > Models, or may be installed automatically by Swell Apps, thereby expanding your database and available API endpoints.

See the Data model customization guide for details on what you can do with custom models, or see Apps model reference to learn how to configure data models in Swell Apps.

Fields

id

stringauto

Unique identifier for the model.

name

stringrequired

Slug-formatted name of the model.

fields

objectrequired

Model fields and their properties applied for each record of a collection.

Fields are named by the key of each property in this object, for example:

"fields": { "name": { "type": "string" }, ... }

While Swell's API supports working with record values that are not defined by a field, it is strongly recommended to define fields for known values.

namespace

string

Optional namespace used in the model's API endpoint, for example "content" results in the endpoint /content/model-name.

version

stringauto

Semver-formatted version number. This value is automatically incremented when the model is modified.

label

string

Plural name of a model collection.

singular

string

Singular name of a model record.

public

boolean

Indicates the model collection and its values are public by default.

public_permissions

object

Restrictive public query parameters for storefront API calls, if applicable.

single

boolean

Indicates the model only only has one record, instead of a collection.

abstract

boolean

Indicates the model can be extended by another model, but cannot be instantiated as a collection.

primary_field

string

The primary field used to look up records in the model collection.

secondary_field

string

Optional secondary field used to look up records in the model collection.

name_field

string

The field used as a label for each record by default.

query

object

Default parameters used when querying the model collection.

storefront

object

Storefront rendering options.

events

object

Model event configuration. By default, each model is configured with created, updated, and deleted events. Custom events can be automatically triggered based on conditions, or manually triggered via API call.

extends

string

Reference to a parent model to extend properties from.

extends_version

stringauto

Automatically assigned version of an extended model, if applicable.

content_id

string

ID of a content model that defined this model, if applicable.

deprecated

boolean

Indicates the model is deprecated and may be removed in a future API version.

date_created

dateauto

Date the model was created.

date_updated

dateauto

Date the model was last updated.

The data model
{
  "version": "1.0.0",
  "label": "Blog",
  "plural": "Blogs",
  "extends": "base",
  "fields": {
    "title": {
      "type": "string",
      "required": true
    },
    "slug": {
      "type": "string",
      "format": "slug",
      "default": {
        "$formula": "slug(title)"
      }
    },
    "author_id": {
      "type": "objectid",
      "required": true
    },
    "author": {
      "type": "link",
      "model": ":users",
      "key": "author_id",
      "data": {
        "fields": "email,name,username"
      }
    },
    "category_id": {
      "type": "objectid",
      "required": true
    },
    "category": {
      "type": "link",
      "model": "content/blog-categories",
      "key": "category_id"
    },
    "content": {
      "type": "string",
      "format": "html",
      "multiline": true
    },
    "summary": {
      "type": "string",
      "format": "html",
      "multiline": true
    },
    "image": {
      "type": "object",
      "fields": {
        "file": {
          "type": "file"
        }
      }
    },
    "tags": {
      "type": "array",
      "value_type": "string",
      "unique": true
    },
    "published": {
      "type": "bool",
      "default": false
    },
    "date_published": {
      "type": "date",
      "label": "Publish Date"
    },
    "meta_title": {
      "type": "string",
      "label": "Page Title"
    },
    "meta_keywords": {
      "type": "string"
    },
    "meta_description": {
      "type": "string",
      "multiline": true
    }
  },
  "query": {
    "sort": "name asc"
  },
  "name_field": "title",
  "secondary_field": "slug",
  "events": {
    "enabled": true,
    "types": [{ "id": "created" }, { "id": "updated" }, { "id": "deleted" }]
  }
}