Collections
List Collections
Returns a list of the collections available in the project.
Query Parameters
How many items to skip when fetching data.
What metadata to return in the response.
Responses
GET /collections
import { createDirectus, rest, readCollections } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(readCollections());
POST /graphql/system
type Query {
collections: [directus_collections]
}
{
"data": [
{
"collection": "messages",
"meta": {
"collection": "messages",
"icon": null,
"note": null,
"display_template": null,
"hidden": false,
"singleton": false,
"translations": null,
"archive_field": null,
"archive_app_filter": true,
"archive_value": null,
"unarchive_value": null,
"sort_field": null,
"accountability": "all",
"color": null,
"item_duplication_fields": null,
"sort": null,
"group": null,
"collapse": "open",
"preview_url": null,
"versioning": false
},
"schema": {
"name": "messages",
"sql": "CREATE TABLE \"messages\" (`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, `user_created` char(36) NULL, `date_created` datetime NULL, `content` text null, CONSTRAINT `messages_user_created_foreign` FOREIGN KEY (`user_created`) REFERENCES `directus_users` (`id`))"
}
}
]
}
Create a Collection
Create a new collection in Directus. The `collection` and `schema` properties are required. To create a collection folder that doesn't have an underlying table, you can set `schema` to `null`. You are able to provide an array of `fields` to be created during the creation of the collection. See the fields object for more information on what properties are available in a field.
Query Parameters
What metadata to return in the response.
Request Body
Unique name of the collection.
The fields contained in this collection. See the fields reference for more information. Each individual field requires field, type, and interface to be provided.
Name of a Google Material Design Icon that's assigned to this collection.
A note describing the collection.
Text representation of how items from this collection are shown across the system.
Whether or not the collection is hidden from the navigation in the admin app.
Whether or not the collection is treated as a single object.
Key value pairs of how to show this collection's name in different languages in the admin app.
Whether or not Content Versioning is enabled for this collection.
What field holds the archive value.
What value to use for "archived" items.
What value to use to "unarchive" items.
Whether or not to show the "archived" filter.
The sort field in the collection.
Responses
Name of the collection. This matches the table name in the database.
Icon displayed in the Data Studio when working with this collection.
Short description displayed in the Data Studio.
How items in this collection should be displayed when viewed relationally in the Data Studio.
Whether or not this collection is hidden in the Data Studio.
Whether or not this collection is treated as a singleton.
How this collection's name is displayed in the different languages in the Data Studio.
What field in the collection holds the archived state.
What value the archive field should be set to when archiving an item.
What value the archive field should be set to when unarchiving an item.
What field holds the sort value on the collection. The Data Studio uses this to allow drag-and-drop manual sorting.
What data is tracked. One of all
, activity
.
What fields are duplicated during "Save as copy" action of an item in this collection.
What sort order of the collection relative to other collections of the same level.
The name of the parent collection.
What is the default behavior of this collection or "folder" collection when it has nested collections. One of open
, closed
, locked
.
Whether or not Content Versioning is enabled for this collection.
POST /collections
import { createDirectus, rest, createCollection } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(
createCollection(collection_object)
);
POST /graphql/system
type Mutation {
create_collections_item(data: directus_collections): directus_collections
}
{
"data": {
"collection": "customers",
"translations": [],
"item_duplication_fields": []
}
}
Retrieve a Collection
Retrieves the details of a single collection by its table name.
Query Parameters
Unique identifier of the collection.
What metadata to return in the response.
Responses
Name of the collection. This matches the table name in the database.
Icon displayed in the Data Studio when working with this collection.
Short description displayed in the Data Studio.
How items in this collection should be displayed when viewed relationally in the Data Studio.
Whether or not this collection is hidden in the Data Studio.
Whether or not this collection is treated as a singleton.
How this collection's name is displayed in the different languages in the Data Studio.
What field in the collection holds the archived state.
What value the archive field should be set to when archiving an item.
What value the archive field should be set to when unarchiving an item.
What field holds the sort value on the collection. The Data Studio uses this to allow drag-and-drop manual sorting.
What data is tracked. One of all
, activity
.
What fields are duplicated during "Save as copy" action of an item in this collection.
What sort order of the collection relative to other collections of the same level.
The name of the parent collection.
What is the default behavior of this collection or "folder" collection when it has nested collections. One of open
, closed
, locked
.
Whether or not Content Versioning is enabled for this collection.
GET /collections/{id}
import { createDirectus, rest, readCollection } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(readCollection(collection_name));
POST /graphql/system
type Query {
collections_by_name(name: String!): directus_collections
}
{
"data": {
"collection": "customers",
"translations": [],
"item_duplication_fields": []
}
}
Delete a Collection
Delete an existing collection. Warning: This will delete the whole collection, including the items within. Proceed with caution.
Query Parameters
Unique identifier of the collection.
Responses
DELETE /collections/{id}
import { createDirectus, rest, deleteCollection } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(deleteCollection(collection_name));
POST /graphql/system
type Mutation {
delete_collections_item(collection: String!): delete_collection
}
Update a Collection
Update the metadata for an existing collection. You can only update the `meta` values of the collection object. Updating the collection name is not supported at this time.
Query Parameters
Unique identifier of the collection.
What metadata to return in the response.
Request Body
Metadata of the collection.
Name of a Google Material Design Icon that's assigned to this collection.
Choose the color for the icon assigned to this collection.
A note describing the collection.
Text representation of how items from this collection are shown across the system.
Whether or not the collection is hidden from the navigation in the admin app.
Whether or not the collection is treated as a single object.
Key value pairs of how to show this collection's name in different languages in the admin app.
Whether or not Content Versioning is enabled for this collection.
What field holds the archive value.
What value to use for "archived" items.
What value to use to "unarchive" items.
Whether or not to show the "archived" filter.
The sort field in the collection.
Responses
Name of the collection. This matches the table name in the database.
Icon displayed in the Data Studio when working with this collection.
Short description displayed in the Data Studio.
How items in this collection should be displayed when viewed relationally in the Data Studio.
Whether or not this collection is hidden in the Data Studio.
Whether or not this collection is treated as a singleton.
How this collection's name is displayed in the different languages in the Data Studio.
What field in the collection holds the archived state.
What value the archive field should be set to when archiving an item.
What value the archive field should be set to when unarchiving an item.
What field holds the sort value on the collection. The Data Studio uses this to allow drag-and-drop manual sorting.
What data is tracked. One of all
, activity
.
What fields are duplicated during "Save as copy" action of an item in this collection.
What sort order of the collection relative to other collections of the same level.
The name of the parent collection.
What is the default behavior of this collection or "folder" collection when it has nested collections. One of open
, closed
, locked
.
Whether or not Content Versioning is enabled for this collection.
PATCH /collections/{id}
import { createDirectus, rest, updateCollection } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(updateCollection(collection_name, partial_collection_object));
POST /graphql/system
type Mutation {
update_collections_item(collection: String!, data: update_directus_collections_input!): directus_collections
}
{
"data": {
"collection": "customers",
"translations": [],
"item_duplication_fields": []
}
}