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

hash
string
diff
object

Responses

Successful request
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

version
integer
directus
string
vendor
string
collections
array
fields
array
relations
array

Responses

Successful request
hash
string
diff
object
POST /schema/diff
Response Example
{
  "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.

Responses

Successful request
version
integer
directus
string
vendor
string
collections
array
fields
array
relations
array
GET /schema/snapshot
Response Example
{
  "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
    }
  ]
}