Schema

Retrieve and update the schema of an instance.

Apply Schema Difference

Update the instance's schema by passing the diff previously retrieved via `/schema/diff` endpoint in the JSON request body or a JSON/YAML file. This endpoint is only available to admin users.

Request Body

data
object

204 Response

Successful request

403 Response

Error: Unauthorized request

error
object
POST /schema/apply

Retrieve Schema Difference

Compare the current instance's schema against the schema snapshot in JSON request body and retrieve the difference. This endpoint is only available to admin users. Alternatively, upload a JSON or YAML schema file. Does not allow different Directus versions and database vendors by default. You can opt in to bypass these checks by passing the `force` query parameter.

Query Parameters

force
boolean

Bypass version and database vendor restrictions.

Request Body

data
object

200 Response

Successful request

data
object

204 Response

No schema difference.

403 Response

Error: Unauthorized request

error
object
POST /schema/diff
Response Example
{
  "data": {
    "diff": {
      "collections": [
        {
          "diff": [
            {}
          ]
        }
      ],
      "fields": [
        {
          "diff": [
            {}
          ]
        }
      ],
      "relations": [
        {
          "diff": [
            {}
          ]
        }
      ]
    }
  }
}

Retrieve Schema Snapshot

Retrieve the current schema. This endpoint is only available to admin users.

Query Parameters

export
string

Saves the API response to a file. Accepts one of csv, json, xml, yaml.

200 Response

Successful request

data
object

403 Response

Error: Unauthorized request

error
object
GET /schema/snapshot
Response Example
{
  "data": {
    "version": 1,
    "collections": [
      {
        "collection": "customers",
        "translations": [],
        "item_duplication_fields": []
      }
    ],
    "fields": [
      {
        "collection": "about_us",
        "field": "id",
        "special": [],
        "options": {},
        "translations": []
      }
    ],
    "relations": [
      {
        "id": 1,
        "many_collection": "directus_activity",
        "many_field": "user",
        "one_collection": "directus_users",
        "one_field": null,
        "one_allowed_collections": [],
        "junction_field": null
      }
    ]
  }
}