> ## Documentation Index
> Fetch the complete documentation index at: https://docs.base44.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sync entity schemas

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

Replaces the specified app's entire set of entities with the one you send, in a single call.

Send every entity the app should have. Any entity the app currently has that is missing from `entityNameToSchema` is deleted. Include `User` to keep its custom fields. Leaving it out drops them. An empty object deletes every entity the app has.

Base44 won't delete an entity that still holds records. If the set you send leaves out an entity that has records, the whole call fails and nothing changes.

This changes the app's live data model, so it takes effect immediately. It doesn't change the file that defines that model in the app's source code. Since Base44 rebuilds the live model whenever the file is written or the app's code is pulled from GitHub, a change made using this endpoint may be reverted.

This endpoint requires the app's source code to be under your control. That includes projects you create with the Base44 CLI and projects you [eject](/developers/references/cli/commands/eject) from the Base44 online app editor. Some managed-source apps may also be granted access.

Entity schemas change on main only, so naming a branch in `branch_id` returns a 409. To add entities or fields on a [branch](/developers/references/app-management/get-started/concepts#branches), use [Send chat message](/api-reference/send-chat-message) with that `branch_id`.



## OpenAPI

````yaml /developers/references/app-management/app-management-openapi.json put /api/apps/{app_id}/entity-schemas
openapi: 3.1.0
info:
  title: Base44 App Management API
  version: 1.0.0
servers:
  - url: https://app.base44.com
security:
  - PersonalAccessTokenAuth: []
paths:
  /api/apps/{app_id}/entity-schemas:
    put:
      summary: Sync entity schemas
      description: >-
        <Info>This API is in beta. Endpoints, fields, and behavior may still
        change, so avoid depending on it in production.</Info>


        Replaces the specified app's entire set of entities with the one you
        send, in a single call.


        Send every entity the app should have. Any entity the app currently has
        that is missing from `entityNameToSchema` is deleted. Include `User` to
        keep its custom fields. Leaving it out drops them. An empty object
        deletes every entity the app has.


        Base44 won't delete an entity that still holds records. If the set you
        send leaves out an entity that has records, the whole call fails and
        nothing changes.


        This changes the app's live data model, so it takes effect immediately.
        It doesn't change the file that defines that model in the app's source
        code. Since Base44 rebuilds the live model whenever the file is written
        or the app's code is pulled from GitHub, a change made using this
        endpoint may be reverted.


        This endpoint requires the app's source code to be under your control.
        That includes projects you create with the Base44 CLI and projects you
        [eject](/developers/references/cli/commands/eject) from the Base44
        online app editor. Some managed-source apps may also be granted access.


        Entity schemas change on main only, so naming a branch in `branch_id`
        returns a 409. To add entities or fields on a
        [branch](/developers/references/app-management/get-started/concepts#branches),
        use [Send chat message](/api-reference/send-chat-message) with that
        `branch_id`.
      operationId: sync_schemas_api_apps__app_id__entity_schemas_put
      parameters:
        - name: app_id
          in: path
          required: true
          schema:
            type: string
            description: ID of the app whose entity schemas you want to work with.
            title: App Id
          description: ID of the app whose entity schemas you want to work with.
          example: 6820f3a4e7b91d003c45a1f2
        - name: branch_id
          in: query
          required: false
          schema:
            type: string
            description: >-
              ID of the branch to work on, as returned by [List
              branches](/api-reference/list-branches). Omit it to work on the
              app's main branch.
            title: Branch Id
          description: >-
            ID of the branch to work on, as returned by [List
            branches](/api-reference/list-branches). Omit it to work on the
            app's main branch.
          example: 68f1a2b3c4d5e6f708192a3b
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SyncEntitySchemasRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SyncEntitySchemasResponse'
        '400':
          description: >-
            An entity name is empty or has characters other than letters,
            numbers, and underscores. It also fires when a schema is not a valid
            JSON Schema, the `User` schema redeclares `email` or `full_name`, a
            schema sets row-level security rules Base44 cannot enforce, or a
            schema newly declares a keyword Base44 does not implement (such as
            `unique`). The sync would delete an entity whose schema doesn't
            allow it to be deleted: error code `entity_not_deletable`, with the
            names in `details.entity_names`.
        '401':
          description: Missing or invalid credentials.
        '403':
          description: >-
            You don't have editor access to this app, or your workspace API key
            lacks the `apps:deploy` scope.
        '404':
          description: App not found, or no branch you can see has this `branch_id`.
        '409':
          description: >-
            Main is protected (`branch_protected`), or `branch_id` names a
            branch (`operation_blocked_on_branch`). The reason is in
            `extra_data.reason`. An app that changes only when you create a new
            version and publish it returns `changes_through_versions` in the
            standard error envelope, and nothing is changed.
        '422':
          description: >-
            The request body is missing, or `entityNameToSchema` is missing, is
            not an object, or maps a name to something other than an object.
            Whether each value is a usable JSON Schema is checked after this and
            returns a 400. It also fires when the entity store rejects a schema
            it cannot store, such as one with an empty property name or a number
            too large to store. Fix the schema and send it again.
        '428':
          description: >-
            Entities the sync would delete still have records. Delete them first
            — the message names every one of them, so they can be cleared in one
            pass.
        '503':
          description: >-
            Database temporarily unavailable (`database_unavailable`): the data
            cluster did not answer in time. Retry after the `Retry-After`
            seconds.
          headers:
            Retry-After:
              description: Seconds to wait before retrying.
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
              examples:
                database_unavailable:
                  summary: database_unavailable
                  value:
                    error:
                      code: database_unavailable
                      message: Database temporarily unavailable, please retry
                      details: {}
      security:
        - PersonalAccessTokenAuth:
            - full_access
        - WorkspaceApiKeyAuth:
            - apps:deploy
        - WorkspaceApiKeyBearerAuth:
            - apps:deploy
components:
  schemas:
    SyncEntitySchemasRequest:
      properties:
        entityNameToSchema:
          additionalProperties:
            additionalProperties: true
            type: object
          type: object
          title: Entitynametoschema
          description: >-
            The app's complete set of entities, keyed by entity name. Each value
            is that entity's [JSON
            Schema](/developers/backend/resources/entities/entity-schemas),
            which needs `"type": "object"` and a `properties` object, plus any
            `required` fields and [row-level security
            rules](/developers/backend/resources/entities/security) under `rls`.
            Any entity the app currently has that this map leaves out is
            deleted.
          example:
            Invoice:
              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
      type: object
      required:
        - entityNameToSchema
      title: SyncEntitySchemasRequest
    SyncEntitySchemasResponse:
      properties:
        created:
          items:
            type: string
          type: array
          title: Created
          description: Entities that did not exist before and were added.
          example:
            - Invoice
        updated:
          items:
            type: string
          type: array
          title: Updated
          description: Entities that already existed and were replaced.
          example:
            - Customer
        deleted:
          items:
            type: string
          type: array
          title: Deleted
          description: Entities the app had and the request left out, which were removed.
          example:
            - LegacyOrder
        warnings:
          items:
            type: string
          type: array
          title: Warnings
          description: >-
            Row-level security rules Base44 stored but can't enforce. The sync
            still applied, so an entity named here exists with a rule that isn't
            protecting anything. Base44 reports a rule this way only for an
            entity the sync adds fresh (one that didn't exist in the app
            before). On an entity the app already has, a new or changed rule of
            this kind fails the call with a 400. An unchanged unenforceable rule
            on an existing entity is left in place silently and doesn't appear
            here.
          example:
            - >-
              Invalid RLS rule in Invoice: "properties.total.rls.delete" —
              field-level delete rules are not enforced — delete removes the
              whole record (there is no field-level delete gate); put the
              restriction in a top-level rls.delete instead.
      type: object
      required:
        - created
        - updated
        - deleted
        - warnings
      title: SyncEntitySchemasResponse
      description: >-
        What a schema sync changed, split into created, updated, and deleted
        entities.
    StandardErrorEnvelope:
      properties:
        error:
          $ref: '#/components/schemas/StandardError'
          description: What went wrong.
      type: object
      required:
        - error
      title: StandardErrorEnvelope
      description: The error body returned in the standard envelope.
    StandardError:
      properties:
        code:
          type: string
          title: Code
          description: >-
            Stable machine-readable cause of the failure. Match on this, not on
            `message`.
          example: not_found
        message:
          type: string
          title: Message
          description: Human-readable explanation. It isn't a stable contract.
          example: App not found
        details:
          additionalProperties: true
          type: object
          title: Details
          description: >-
            Structured context for the failure, or an empty object when there's
            none.
          example: {}
      type: object
      required:
        - code
        - message
      title: StandardError
  securitySchemes:
    PersonalAccessTokenAuth:
      type: http
      scheme: bearer
      description: >-
        Personal access token, sent as `Authorization: Bearer <token>`. Each
        operation lists the permission it needs: `read_only` or `full_access`. A
        full-access token can call every operation. A read-only token can call
        only the operations that list `read_only`; anything else returns 403
        `read_only_credential_route_not_allowed`.
    WorkspaceApiKeyAuth:
      type: apiKey
      in: header
      name: api_key
      description: >-
        Workspace API key, sent as `api_key: <key>`. Each operation that accepts
        one lists what the key needs: a permission, `read_only` or
        `full_access`, like a personal access token, or a scope. A key without
        the scope gets 403 `workspace_api_key_scope_required`.
    WorkspaceApiKeyBearerAuth:
      type: http
      scheme: bearer
      description: >-
        Workspace API key, sent as `Authorization: Bearer <key>`. Accepted
        wherever `api_key` is, with the same permission.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.