Backend API
Content models are a layer above data models and have a simpler configuration syntax and allow for field values to be editable in the dashboard. They provide most of the functionality you'd expect from a dedicated CMS—with the additional benefit of making content available in the same API as standard models like products. While data models are limited to primitive field types like string, content models can define input UIs for fields like phone_number or url to provide a better editing experience. This ensures that the data is entered in the correct format.
Refer to the Data model customization guide for details on how to work with content models.
Fields
id
stringautoUnique identifier for the model.
label
stringPlural name of the content model collection.
name
stringrequiredautoSystem name of the model. Defaults to [collection].[root].
source_type
enumrequiredautoIndicates the source of the content model, app or custom. The value is automatically set to custom when created from the Swell dashboard.
Possible enum values:
app_id
objectIdID of a Swell App that defined this model, if applicable.
date_created
dateautoDate the model was created.
date_updated
dateautoDate the model was last updated.
public
booleanIndicates that collection records are accessible by a public API call.
fields
array of fieldrequiredContent fields and their properties applied for each record of a collection.
field.id
stringrequiredString ID of the content field representing the name of a model field. This must be unique when combined with the root property.
For example: my_field
field.label
stringOptional label of the field used in the Swell dashboard.
field.description
stringA brief description of the field.
field.type
stringrequiredType of the field. Content fields present a configurable UI in the Swell dashboard, and also apply relevant data types to their respective data model, as defined by collection.
Basic types have a number of ui options that affect how the field is displayed in the dashboard.
- short_text
- ui: default (text), slug, email, phone, url
- data type: string
- long_text
- ui: default (textarea), rich_text, basic_html, rich_html, markdown, liquid
- data type: string
- boolean
- ui: default (checkbox), toggle
- data type: bool
- select
- ui: default (dropdown), radio, checkboxes
- data type: array<string>
- number
- ui: default (integer), float, currency, slider
- data type: int, float, currency
- date
- ui: default (date), time, datetime
- data type: date
- asset
- ui: default (flexible), image, video, document
- data type: file
- tags
- Default ui renders a tag input
- data type: array<string>
- color
- Default ui renders a color picker
- data type: string
- icon
- Default ui renders an icon picker
- data type: string
- lookup
- Default ui render a lookup component
- data type: objectid
- collection
- An array of nested objects
- data type: array<object>
- field_group
- Wrapper that renders a group fields vertically
- field_row
- Wrapper that renders a group fields horizontally
The following are UI-specific aliases for configurations intended to help simplify many CMS use cases. When used as a type, their respective properties are automatically applied to the field and can each be overridden.
- text
- type: short_text
- textarea
- type: long_text
- rich_text
- type: long_text
- ui: rich_text
- checkbox
- type: boolean
- checkboxes
- type: select
- ui: checkboxes
- multi: true
- toggle
- type: boolean
- ui: toggle
- radio
- type: select
- ui: radio
- dropdown
- type: select
- integer
- type: number
- digits: 0
- float
- type: number
- digits: 2
- currency
- type: number
- ui: currency
- percent
- type: number
- unit: %
- slider
- type: number
- ui: slider
- increment: 1
- time
- type: date
- ui: time
- datetime
- type: date
- ui: datetime
- phone
- type: short_text
- ui: phone
- email
- type: short_text
- ui: email
- url
- type: short_text
- ui: url
- slug
- type: short_text
- ui: slug
- html
- type: long_text
- ui: basic_html
- basic_html
- type: long_text
- ui: basic_html
- rich_html
- type: long_text
- ui: rich_html
- markdown
- type: long_text
- ui: markdown
- liquid
- type: long_text
- ui: liquid
- image
- type: asset
- asset_types: [image]
- document
- type: asset
- asset_types: [document]
- video
- type: asset
- asset_types: [video]
- child_collection
- type: collection
- child: true
- product_lookup
- type: lookup
- collection: products
- variant_lookup
- type: lookup
- collection: products:variants
- category_lookup
- type: lookup
- collection: categories
- customer_lookup
- type: lookup
- collection: accounts
field.ui
stringEnumerated UI-types, when combined with type, allows you to render various different components in the Swell dashboard for the same underlying data field. Each ui only works relative to a specific type. See the field.type documentation for details.
Note: ui values are different than type aliases as documented, however they may share the same name.
field.fields
array of fieldRequired for field_group, field_row, and collection only, defines the nested fields of the group. The fields of a group are of the same schema as the top-level fields property.
field.field
objectrequiredNested content field.
field.value_type
enumOptionally specify the data type used to store this value in a model collection. Content field type is cast to value_type when a record is created or updated. Defaults to the appropriate data type for a given content field type.
Possible enum values:
field.item_types
array of item_typeFor collection only, define groups of nested fields that are applied to collection records. In the respective data model, these are defined as object_types according to the nested content field schema.
item_type.id
stringrequiredID of the item type. This becomes the key of a related model collection's object_types.
item_type.name
stringOptional name of the item type used in the Swell dashboard.
item_type.fields
array of fieldContent fields displayed for the item type, using the same schema as the top-level fields property.
field.field
objectrequiredfield.conditions
objectA query object used to match record values. When matched, the field is visible, otherwise it is hidden. Field conditions support the equivalent format and operators of query filtering.
field.required
booleanIndicates the field must be defined with a non-empty value when the record is created or updated.
field.default
mixedGlobal default value of the field, applied to all records at runtime when retrieved by the API. The Swell dashboard supports overriding this value per-record, and also the ability to reset the value to the global default.
If fallback is set to false, then the default is stored on the record locally when created from the Swell dashboard.
field.public
booleanIndicates that a field value is made accessible by a public API call, assuming the parent content model does not have public: true.
field.fallback
booleanIndicates the default value should fallback to the global default. Defaults to true.
field.enum
array of valueEnumerated set of values accepted by the system.
field.format
stringAutomatically format the value of a string field. This may be an alternative to a more complex formula for simple use cases.
One of:
- uppercase: value => VALUE
- lowercase: VALUE => value
- underscore: TextValue => text_value
- slug: TextValue => text-value
- slugid: TextValue.Example => text-value.example
- currency-code: usd => USD
- url: example.com => https://example.com
- email: user name@example.com => user+name@example.com
- semver: 1 => 1.0.0
- password: example => bcrypt(example)
- Password-formatted fields are automatically hashed with the bcrypt algorithm.
field.formula
stringAn expression used to calculate the value of the field when a record is created or updated. See Formula documentation for more details.
field.readonly
booleanIndicates the field cannot be changed after initially being defined. Note: a formula field may still change the value dynamically.
field.unique
mixedIf set to true, indicates the value must be unique across the entire collection. If set as an array of adjacent fields, indicates the combination of values must be unique across the entire collection.
For example, the following would specify a field must be unique when combined with account_id:
"unique": ["account_id"]
field.localized
booleanIndicates that a string or currency value can be localized by locale and currency codes in the Swell dashboard.
field.hint
stringText hint typically displayed below the field input in the Swell dashboard.
field.root
mixedThe object path data fields will be applied to in the respective model collection. For example, on the accounts collection, to root a field to the shipping object, set root: shipping.
If undefined, the field will be rooted to the model's content object, which is accessible by a public API call.
If true, the field will be rooted at the top-level of the model schema.
field.admin_span
intNumber of columns for the field to span, between 1 and 4. The Swell dashboard interface supports a grid of up to 4 columns on a page. Defaults to 4.
field.admin_zone
stringSpecifies the area of the Swell admin dashboard for the field to appear. Most standard collections have pre-defined zones that are distributed throughout the dashboard UI. Some zones will change the root of the content fields, for example scoping fields to a variant record instead of the parent product.
If the admin_zone is empty, the field is hidden from the UI.
The following are zones displayed by each standard collection. Note: app-defined or custom collections only support the content zone.
products:
- details: The main details section.
- pricing: The pricing section.
- options: The options section.
- option-edit: The interface to edit an option.
- root: options
- option-value-edit: The interface to edit an option value.
- root: options.values
- variant-edit: The interface to edit a variant.
- root: variants
- related: The related products section.
- attributes: The attributes tab.
- inventory: The inventory tab.
- shipping: The shipping tab.
- content: The content section at the bottom of the page.
categories:
- details: The main details section.
- content: The content section at the bottom of the page.
accounts:
- details: The main details section.
- contact: The interface used to edit contact information.
- billing: The interface used to edit billing information.
- root: billing
- shipping: The interface used to edit shipping information.
- root: shipping
orders:
- details: The main details section.
- content: The content section at the bottom of the page.
subscriptions:
- details: The main details section.
- content: The content section at the bottom of the page.
invoices:
- details: The main details section.
- content: The content section at the bottom of the page.
carts:
- details: The main details section.
- content: The content section at the bottom of the page.
payments:
- charge: The interface to charge a payment method.
- refund: The interface to refund a payment.
- root: refunds
shipments:
- order: The interface for an order fulfillment.
returns:
- order: The interface for an order return.
attributes:
- content: The content section at the bottom of the page.
giftcards:
- content: The content section at the bottom of the page.
coupons:
- content: The content section at the bottom of the page.
promotions:
- content: The content section at the bottom of the page.
purchaselinks:
- content: The content section at the bottom of the page.
content/pages:
- content: The content section at the bottom of the page.
content/blogs:
- content: The content section at the bottom of the page.
field.multi
booleanFor select only, indicates the value should support multiple selections.
field.model
stringFor lookup only, specifies the model to query when looking up records in the Swell dashboard.
field.key
stringFor lookup only, optionally specifies the foreign key to reference the primary key of a linked collection. Defaults to the primary key of the linked collection.
field.key_field
stringFor lookup only, optionally specifies the field containing a foreign key to reference the primary key of a linked collection. Important: a key field is automatically created for a lookup field in the format of [lookup-field-name]_id.
field.limit
intFor lookup only, limits the number of results to display in a lookup query UI.
field.min
floatRequires a minimum value of a number field.
field.max
floatRequires a maximum value of a number field.
field.digits
intFor number only, determines the number of decimal digits rounded to.
field.item_label
stringFor collection only, refers to the collection field that should be used as a label in the collection list.
field.icon
stringFor collection only, specifies an icon to be displayed next to each row of a collection list.
field.asset_types
array of asset_typeFor asset only, indicates the file types acceptable for upload. Defaults to allow any file type.
defaults
objectautoAggregate global default values derived from field defaults. These values are automatically applied to API responses when using the $content: true operator.
views
array of viewContent views allowing you to configure different layouts for list and record pages. List views allow you to add fields and filters to collection lists, while record views allows you to add fields to record pages.
view.id
stringrequiredID of the view. List views must have id: list, while other IDs are always evaluated as record type views.
Standard view IDs:
- list: Configures columns (fields) in a collection list.
- record: Configures fields on a record page.
- new: Configures fields on a record page only when creating a new record.
- edit: Configures fields on a record page only when editing an existing record.
view.type
stringType of the view. Either list, record, edit, or new. Defaults to list if it matches the view id, or record otherwise.
view.label
stringOptional label of the view to display in the Swell dashboard.
view.fields
array of fieldFields to be displayed in the view. The only required field property is id, however you may override any field property to change its behavior in the view layout specifically.
View fields are used in both list and record layouts, while list views may ignore certain properties that are only relevant to record views.
field.field
objectrequiredField configuration object. The fields of a view are of the same schema as the top-level fields property, however only field.id is required.
view.tabs
array of tabFor list only, defines query tabs that filter results in a collection.
tab.id
stringrequiredCustom ID used in the URL when a user navigates to this tab. Typically a simplified version of the label.
tab.label
stringrequiredLabel displayed as the tab text in the collection list UI.
tab.query
objectQuery used to filter collection results when the tab is active.
query.where
objectA query object used to filter records in a collection list. Support the equivalent format and operators of query filtering.
query.limit
intLimits the number of results displayed in a page by default.
query.sort
stringSpecifies the default sort directive of the collection query. For example: sort: name asc.