Skip to content

Create Entity

Creates a new Entity model (a content type) in your project’s schema, with its list of fields. Once created, you can start adding content of that type with POST /content.

This is the schema-management counterpart of the content endpoints: instead of creating an entry, it creates the type that entries belong to.

Endpoint

shell
curl -X POST https://api.contentisland.net/api/1.0/model/entity \
--header 'Authorization: Bearer YOUR_WRITE_TOKEN' \
--header 'Content-Type: application/json' \
--data '{ ... }'

Body

interface CreateEntityPayload {
name: string; // model name (see "Name rules" below)
fieldList: FieldSpec[]; // at least one field, in order
}
interface FieldSpec {
id?: string; // omit when creating — the server assigns one
name: string; // field name, unique within the model
type: FieldType; // see "Field types" below
relatedModelId?: string; // required for "relation" / "enum" types
isArray?: boolean; // true → the field stores a list of values (default false)
validations?: Validation[]; // see "Validations" below
}
interface Validation {
name: string; // 'required' | 'unique' | 'min-length' | 'max-length' | 'media-type'
customArgs?: any; // depends on the validation (see the table)
}
NameDescription
nameThe model name. Must satisfy the name rules and be unique across the project’s models.
fieldListThe fields of the entity, in order. At least one field is required. Field order is preserved.

Field types

Each field’s type is one of the primitives below, or one of the two relational types.

typeStores
short-textA single line of text.
long-textA multi-line / rich-text block.
numberA numeric value.
dateA calendar date.
date-timeA date together with a time.
mediaA reference to an uploaded file (image, document, …).
booleantrue / false.
colorA color value.
relationA reference to another entity. Requires relatedModelId.
enumA reference to an enum. Requires relatedModelId.

Set isArray: true on any field to make it store a list of that type (e.g. an array of short-text tags, or a multi-relation).

Validations

Add validations to a field to constrain its values. They are stored when you create the model and enforced when content is saved or published.

namecustomArgsEnforced at
requiredpublish preflight
uniquesave
min-length{ "length": <number> }publish preflight
max-length{ "length": <number> }publish preflight
media-type{ "allowedExtensions": [{ "name": ".png", "category": "image" }, …] }publish preflight

Name rules

A model name (and the same rules apply to field names) must:

  • match the pattern /^[a-zA-Z0-9_ -]+$/ (letters, digits, spaces, _, -),
  • be at most 128 characters,
  • not be a reserved field-type word (short-text, long-text, number, date, date-time, media, boolean, color),
  • be unique across the project’s models. Field names must be unique within the model (case-insensitive).

Example

A Article entity referencing an existing Author entity (relation) and a Size enum:

shell
curl -X POST https://api.contentisland.net/api/1.0/model/entity \
--header 'Authorization: Bearer YOUR_WRITE_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"name": "Article",
"fieldList": [
{
"name": "title",
"type": "short-text",
"validations": [
{ "name": "required" },
{ "name": "max-length", "customArgs": { "length": 120 } }
]
},
{ "name": "body", "type": "long-text" },
{ "name": "views", "type": "number" },
{
"name": "cover",
"type": "media",
"validations": [
{
"name": "media-type",
"customArgs": {
"allowedExtensions": [
{ "name": ".png", "category": "image" },
{ "name": ".jpg", "category": "image" }
]
}
}
]
},
{ "name": "tags", "type": "short-text", "isArray": true },
{ "name": "writtenBy", "type": "relation", "relatedModelId": "660f5b8a3a1c2d4e7f8b9012" },
{ "name": "size", "type": "enum", "relatedModelId": "660f5b8a3a1c2d4e7f8b34cd" }
]
}'

Response

On success the endpoint returns 201 Created with the id of the new model:

interface SaveModelResponse {
id: string;
}
{
"id": "660f5b8a3a1c2d4e7f8b9012"
}

Status Codes

CodeDescription
201The model was created. The response body contains the new model id.
400Invalid payload — bad name (format / length / reserved / duplicate), empty fieldList, duplicate field names, or a relation/enum field pointing at the wrong target type.
401Unauthorized. The token is missing, malformed or expired.
403Forbidden. The token does not have write permissions — use a Write Token.
404A relatedModelId does not match any model in the project.
500Internal server error.