Utilities
Clear the Internal Cache
Resets the data cache of Directus. Optionally, can also clear system cache. This endpoint is only available to admin users.
Query Parameters
Clear the system cache as well
Responses
import { createDirectus, rest, clearCache } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(clearCache());
Export Data to a File
Export a larger data set to a file in the file library.
Query Parameters
Collection identifier
Request Body
What file format to save the export to. One of csv, csv_utf8, xml, json, yaml
Control what fields are being returned in the object.
Filter by items that contain the given search query in one of their fields.
How to sort the returned items.
Set the maximum number of items that will be returned
How many items to skip when fetching data.
Cursor for use in pagination. Often used in combination with limit.
Retrieve relational items excluding reverse relations when using wildcard fields.
Unique identifier for the file.
Where the file is stored. Either local for the local filesystem or the name of the storage adapter (for example s3).
Name of the file on disk. By default, Directus uses a random hash for the filename.
How you want to the file to be named when it's being downloaded.
Title for the file. Is extracted from the filename on upload, but can be edited by the user.
MIME type of the file.
Virtual folder where this file resides in.
Who uploaded the file.
When the file was created.
Character set of the file.
Size of the file in bytes.
Width of the file in pixels. Only applies to images.
Height of the file in pixels. Only applies to images.
Duration of the file in seconds. Only applies to audio and video.
Where the file was embedded from.
Description for the file.
Where the file was created. Is automatically populated based on Exif data for images.
Tags for the file. Is automatically populated based on Exif data for images.
When the file was last uploaded/replaced.
Responses
import { createDirectus, rest, utilsExport } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(
utilsExport(
'collection_name',
'file_format',
{
query_type: {
field: {
query_operation: 'value',
},
},
},
{
file: {
file_field: 'value',
},
}
)
);
Import Multiple Collections
Import flat data for multiple related collections in a single request. Relations are resolved from the schema so collections are imported in dependency order and primary keys (and the foreign keys referencing them) are remapped. The payload is uploaded as a JSON file (`multipart/form-data`) containing an array of `{ collection, items }` objects, for example: ```json [ { "collection": "authors", "items": [{ "id": "123", "name": "Lorem Ipsum" }] }, { "collection": "articles", "items": [{ "id": "123", "title": "Hello World", "author": "123" }] } ] ```
Query Parameters
add inserts new items and remaps conflicting primary keys, merge upserts items. Defaults to add.
When true, no data is persisted; the computed id mappings are still returned.
Only valid with mode=merge. Deletes any existing records in the imported collections whose primary key is absent from the import, mirroring the payload. Destructive.
Responses
Whether the changes were committed. false for a dry run.
import { createDirectus, rest, utilsImportBatch } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const formData = new FormData();
formData.append('file', raw_file);
const result = await client.request(utilsImportBatch(formData, { mode: 'add' }));
{
"data": {
"collections": {}
}
}Import Data from File
Import multiple records from a JSON or CSV file into a collection.
Query Parameters
Collection identifier
Responses
import { createDirectus, rest, utilsImport } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const formData = new FormData();
formData.append('file', raw_file);
const result = await client.request(utilsImport(formData));
Get a Random String
Returns a random string of given length.
Query Parameters
Length of the random string.
Responses
import { createDirectus, rest, randomString } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(randomString(length));
{
"data": "1>M3+4oh.S"
}Manually Sort Items in Collection
Re-sort items in collection based on start and to value of item.
Query Parameters
Collection identifier
Request Body
Primary key of item to move
Primary key of item where to move the current item to
Responses
import { createDirectus, rest, utilitySort } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(utilitySort(collection_name, id_item_to_move, id_item_moving_to));
Revert to a Revision
Revert an item to its state at the given revision.
Query Parameters
Unique identifier of the revision to revert to.
Responses
// Not supported in Directus SDK
Set Up Translations
Scaffold a translations collection, languages collection, fields, and relations for a given collection. Admin only.
Request Body
Collection to enable translations on.
One or more field names to create on the translations collection.
Name for the translations collection. Defaults to {collection}_translations.
Name of the languages collection to use or create. Defaults to languages.
Foreign key field on the translations collection pointing to the parent. Defaults to {collection}_id.
Foreign key field on the translations collection pointing to the language. Defaults to languages_code.
Create the languages collection if it does not exist. Defaults to true.
Seed the languages collection with default language entries. Defaults to true.
Responses
Whether a new translations collection was created.
Name of the translations collection.
Name of the languages collection (only present when a new translations collection was created).
Names of the fields created on the translations collection.
// Not supported in Directus SDK
{
"data": {
"fields": []
}
}