Backend API

Fields
idstringauto

Unique identifier for the model.

namestringrequired

Slug-formatted name of the model.

fieldsobjectrequired

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.

namespacestring

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

versionstringauto

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

labelstring

Plural name of a model collection.

singularstring

Singular name of a model record.

publicboolean

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

public_permissionsobject

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

singleboolean

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

abstractboolean

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

primary_fieldstring

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

secondary_fieldstring

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

name_fieldstring

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

name_patternstring

A string pattern used to derive record names with string substitution, which can reference any field in the record. If defined, it is used instead of name_field.

For example: {name} - {sku}

The pattern may also reference nested or link fields, for example:

{parent.name} - {sku}

queryobject

Default parameters used when querying the model collection.

storefrontobject

Storefront rendering options.

eventsobject

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.

extendsstring

Name of a parent model to extend properties from.

For example, to extend the standard product model in the definition of a new model:

"extends": "products"

All properties of the extended model will be inherited and merged under the new schema. Any property can be overridden or modified in the definition of the extending model, including field attributes.

For example, if a parent model has an optional field sku and you want to make it required in the extending model:

models/custom-products.json
{
  "extends": "products",
  "fields": {
    "sku": {
      "required": true
    }
  }
}
extends_versionstringauto

Automatically assigned version of an extended model, if applicable.

content_idstring

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

deprecatedboolean

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

date_createddateauto

Date the model was created.

date_updateddateauto

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" }]
  }
}