Utilities
Directus comes with various utility endpoints you can use to simplify your development flow.
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
POST /utils/cache/clear
import { createDirectus, rest, clearCache } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(clearCache());
mutation {
utils_cache_clear
}
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
[undefined]
Responses
Successful request
POST /utils/export/{collection}
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',
},
}
)
);
// Not currently available in GraphQL
Generate a Hash.
Generate a hash for a given string.
Request Body
[undefined]
Responses
Successful request
data
string
POST /utils/hash/generate
import { createDirectus, rest, generateHash } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(generateHash(string_to_hash));
POST /graphql/system
type Mutation {
utils_hash_generate(string: String!): String
}
Response Example
{
"data": "$argon2i$v=19$m=4096,t=3,p=1$pOyIa/zmRAjCVLb2f7kOyg$DasoO6LzMM+6iKfzCDq6JbsYsZWLSm33p7i9NxL9mDc"
}
Verify a Hash.
Verify a string with a hash.
Request Body
[undefined]
Responses
Successful request
data
boolean
POST /utils/hash/verify
import { createDirectus, rest, verifyHash } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(verifyHash(string_to_verify, hash));
POST /graphql/system
type Mutation {
utils_hash_verify(hash: String!, string: String!): Boolean
}
Response Example
{
"data": true
}
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
POST /utils/import/{collection}
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));
// Not currently available in GraphQL
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
GET /utils/random/string
import { createDirectus, rest, randomString } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(randomString(length));
POST /graphql/system
type Mutation {
utils_random_string(length: Int): String
}
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
[undefined]
Responses
Successful request
POST /utils/sort/{collection}
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));
POST /graphql/system
type Mutation {
utils_sort(collection: String!, item: ID!, to: ID!): Boolean
}