Create entity schema

<Info>This API is in beta. Endpoints, fields, and behavior may still change, so avoid depending on it in production.</Info>

Adds a new entity to the app and makes it queryable right away.

Send the entity name and its JSON Schema. The name must contain only letters, numbers, and underscores. Put the entity's properties and required fields in entity_schema, and its row-level security rules under rls. Base44 adds a name key holding the entity name to the schema it stores and returns.

<Warning>This changes the app's live schema right away, but it does not change the entity definition in the app's source code. Base44 rebuilds the live schema from the source files whenever the app's code changes, which reverts anything you set here. Change the code itself when you need the edit to last.</Warning>

You cannot create User, which is built in. Use Update entity schema with User to add custom fields to it.

A name the app already uses returns a 409. The one exception is a workspace API key resending a byte-identical schema, which returns a 200 so a repeated deploy is safe. The same request with a personal API key still returns a 409.

<Note>This endpoint accepts a personal API key, or a workspace API key with the apps:deploy scope.</Note>

post/api/apps/{app_id}/entity-schemas

Path parameters

app_idstring required

ID of the app whose entity schemas you want.

ID of the app whose entity schemas you want.

Request body

entity_namestring required

Name for the new entity. Letters, numbers, and underscores only. Cannot be User.

entity_schemaobject required

The entity's JSON Schema: its properties, its required fields, and any row-level security rules under rls.

Example request

{
  "entity_name": "Invoice",
  "entity_schema": {
    "name": "Invoice",
    "properties": {
      "amount": {
        "description": "Total amount in cents",
        "type": "number"
      },
      "status": {
        "enum": [
          "draft",
          "sent",
          "paid"
        ],
        "type": "string"
      }
    },
    "required": [
      "amount"
    ],
    "rls": {
      "read": {
        "created_by": "{{user.email}}"
      }
    },
    "type": "object"
  }
}

Response

The created entity schema.

entity_namestring required

Name of the entity.

entity_schemaobject required

The entity's stored JSON Schema. For the app's own entities this includes a name key Base44 sets on every write; the User schema does not get one.

Example response

{
  "entity_name": "Invoice",
  "entity_schema": {
    "name": "Invoice",
    "properties": {
      "amount": {
        "description": "Total amount in cents",
        "type": "number"
      },
      "status": {
        "enum": [
          "draft",
          "sent",
          "paid"
        ],
        "type": "string"
      }
    },
    "required": [
      "amount"
    ],
    "rls": {
      "read": {
        "created_by": "{{user.email}}"
      }
    },
    "type": "object"
  }
}

Changes