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

system
boolean

Clear the system cache as well

Responses

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

Collection identifier

Request Body

format
string

What file format to save the export to. One of csv, csv_utf8, xml, json, yaml

query
object
file
object

Responses

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

mode
string

add inserts new items and remaps conflicting primary keys, merge upserts items. Defaults to add.

dryRun
boolean

When true, no data is persisted; the computed id mappings are still returned.

dangerouslyAllowDelete
boolean

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

Successful request
data
object
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' }));
Response Example
{
  "data": {
    "collections": {}
  }
}

Import Data from File

Import multiple records from a JSON or CSV file into a collection.

Query Parameters

collection
string

Collection identifier

Responses

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

Length of the random string.

Responses

Successful request
data
string
import { createDirectus, rest, randomString } from '@directus/sdk';

const client = createDirectus('directus_project_url').with(rest());

const result = await client.request(randomString(length));
Response Example
{
  "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
string

Collection identifier

Request Body

item
number

Primary key of item to move

to
number

Primary key of item where to move the current item to

Responses

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

revision
string

Unique identifier of the revision to revert to.

Responses

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

Collection to enable translations on.

fields
array

One or more field names to create on the translations collection.

translationsCollection
string

Name for the translations collection. Defaults to {collection}_translations.

languagesCollection
string

Name of the languages collection to use or create. Defaults to languages.

parentFkField
string

Foreign key field on the translations collection pointing to the parent. Defaults to {collection}_id.

languageFkField
string

Foreign key field on the translations collection pointing to the language. Defaults to languages_code.

createLanguagesCollection
boolean

Create the languages collection if it does not exist. Defaults to true.

seedLanguages
boolean

Seed the languages collection with default language entries. Defaults to true.

Responses

Successful request
data
object
// Not supported in Directus SDK
Response Example
{
  "data": {
    "fields": []
  }
}