Files
directus/docs/reference/system/operations.md
Bevis Halsey-Perry 60df20d780 Simplified generic examples and consolidated imports for sdk examples in docs. (#19370)
* Simplified generics and imports for items page snippets

* Simplified generics and imports for files page snippets

* Fixing simplified generic snippets in items page

* Simplified generics and imports for activity page snippets

* Simplified generics and imports for collections page snippets

* Simplified generics and imports for dashboards page snippets

* Simplified generics and imports for extensions page snippets

* Simplified generics and imports for fields page snippets

* Simplified generics and imports for flows page snippets

* Simplified generics and imports for folders page snippets

* Simplified generics and imports for notifications page snippets

* Simplified generics and imports for operations page snippets

* Simplified generics and imports for panels page snippets

* Simplified generics and imports for permissions page snippets

* Simplified generics and imports for presets page snippets

* Simplified generics and imports for relations page snippets

* Simplified generics and imports for relations page snippets

* Simplified generics and imports for revisions page snippets

* Simplified generics and imports for roles page snippets

* Consolidated imports for schema page snippets

* Simplified generics and imports for server page snippets

* Simplified generics and imports for settings page snippets

* Fixed mixed up snippets and simplified generics and imports for shares page snippets

* Simplified generics and imports for translation page snippets

* Fixed mixed up snippets and simplified generics and imports for user page snippets

* Simplified generics and imports fo uutilitie pages snippets

* Simplified generics and imports for webhook pages snippets

* Simplified generics and imports for authentication pages snippets

* Consolidated imports for query pages sdk snippets

* Format files

* Update lockfile

* Fix spelling

* Format snippets

* Aling `result` const

* Small clean-ups

- Align `SEARCH` snippets, move "Learn more..." next to other hint
- ids -> IDs
- Other alignments

---------

Co-authored-by: Bevis Halsey-Perry <hi@be7.is>
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
2023-08-08 10:16:23 -04:00

16 KiB

description, readTime, pageClass
description readTime pageClass
REST and GraphQL API documentation on the Operations collection in Directus. 5 min read page-reference

Operations

Operations are the building blocks of Data Flows within Directus.

The Operation Object

id uuid
Primary key of the operation.

name string
Name for the operation.

key string
Key for the operation. Must be unique within a given flow.

type string
Type of operation. One of log, mail, notification, create, read, request, sleep, transform, trigger, condition, or any type of custom operation extensions.

options json
Options depending on the type of the operation.

position_x integer
Position of the operation on the X axis within the flow workspace.

position_y integer
Position of the operation on the Y axis within the flow workspace.

date_created timestamp
Timestamp in ISO8601 when the operation was created.

user_created many-to-one
The user who created the operation. Many-to-one to users.

resolve uuid
The operation triggered when the current operation succeeds (or then logic of a condition operation). Primary key of an operation.

reject uuid
The operation triggered when the current operation fails (or otherwise logic of a condition operation). Primary key of an operation.

flow many-to-one
The flow containing this operation. Many-to-one to flows.

{
	"id": "585b04cd-2821-4dcc-a563-ae5d29ecace2",
	"name": "Log a Message",
	"key": "log_message",
	"type": "log",
	"position_x": 12,
	"position_y": 24,
	"date_created": "2022-05-11T13:14:52Z",
	"user_created": "12e62fd0-29c7-4fd3-b3d3-c7a39933e8af",
	"resolve": "bf4099c0-c54c-4736-ab4e-95e2487595e4",
	"reject": null,
	"flow": "22544db5-93f7-48e2-a028-7ae02c8fe49a"
}

List Operations

List all operations that exist in Directus.

Request

GET /operations

SEARCH /operations

If using SEARCH you can provide a query object as the body of your request.

Learn more about SEARCH ->

POST /graphql/system

type Query {
	operations: [directus_operations]
}
import { createDirectus, rest, readOperations } from '@directus/sdk';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(readOperations(query_object));

Query Parameters

Supports all global query parameters.

Response

An array of up to limit operation objects. If no items are available, data will be an empty array.

Example

GET /operations

SEARCH /operations

POST /graphql/system

query {
	operations {
		id
		name
		key
	}
}
import { createDirectus, rest, readOperations } from '@directus/sdk';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	readOperations({
		fields: ['*'],
	})
);

Retrieve an operation

List an existing operation by primary key.

GET /operations/:id

POST /graphql/system

type Query {
	operations_by_id(id: ID!): directus_operations
}
import { createDirectus, rest, readOperation } from '@directus/sdk';

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

const result = await client.request(readOperation(operation_id, query_object));

Request

Query Parameters

Supports all global query parameters.

Response

Returns the requested operation object.

Example

GET /operations/3c636d1c-4eb2-49cd-8a6d-3ec571ab3390

POST /graphql/system

query {
	operations_by_id(id: 42) {
		id
		name
		key
	}
}
import { createDirectus, rest, readOperation } from '@directus/sdk';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	readOperation('0691f58d-ed72-40ea-81b4-81c0f1e83262', {
		fields: ['*'],
	})
);

Create an Operation

Create a new operation.

POST /operations

Provide an operation object as the body of your request.

POST /graphql/system

type Mutation {
	create_operations_item(data: create_directus_operations_input!): directus_operations
}
import { createDirectus, rest, createOperation } from '@directus/sdk';

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

const result = await client.request(createOperation(operation_object));

Request

Query Parameters

Supports all global query parameters.

Request Body

A partial operation object.

Response

Returns the operation object for the created operation.

Example

POST /operations

{
	"name": "My Log",
	"key": "my_log",
	"type": "log"
}

POST /graphql/system

mutation {
	create_operations_item(data: { name: "My Log", key: "my_log", type: "log" }) {
		id
		name
		key
	}
}
import { createDirectus, rest, createOperation } from '@directus/sdk';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	createOperation({
		key: 'my_log',
		type: 'log',
		position_x: '25',
		position_y: '25',
		flow: '90a0fdd5-e760-4b4c-ac22-c14d48d44f26',
	})
);

Create Multiple Operations

Create multiple new operations.

Request

POST /operations

Provide an array of operations objects as the body of your request.

[
	{
		"operations_1_field_1": "value_1",
		"operations_1_field_2": "value_2",
		"operations_1_field_3": "value_3"
	},
	{
		"operations_2_field_1": "value_4",
		"operations_2_field_2": "value_5",
		"operations_2_field_3": "value_6"
	}
]

POST /graphql/system

type Mutation {
	create_operations_items(data: [create_directus_operations_input!]!): [directus_operations]
}
import { createDirectus, rest, createOperations } from '@directus/sdk';

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

const result = await client.request(createOperations(operations_object_array));

Query Parameters

Supports all global query parameters.

Request Body

An array of partial operation objects.

Response

Returns the operation object for the created operation.

Example

POST /operations

[
	{
		"name": "My Log",
		"key": "my_log",
		"type": "log"
	},
	{
		"name": "Send Notification",
		"key": "send_notification",
		"type": "notification"
	}
]

POST /graphql/system

mutation {
	create_operations_items(
		data: [
			{ name: "My Log", key: "my_log", type: "log" }
			{ name: "Send Notification", key: "send_notification", type: "notification" }
		]
	) {
		id
		name
		key
	}
}
import { createDirectus, rest, createOperations } from '@directus/sdk';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	createOperations([
		{
			key: 'my_log',
			type: 'log',
			position_x: '40',
			position_y: '40',
			flow: '90a0fdd5-e760-4b4c-ac22-c14d48d44f26',
		},
		{
			key: 'my_other_log',
			type: 'log',
			position_x: '20',
			position_y: '40',
			flow: '90a0fdd5-e760-4b4c-ac22-c14d48d44f26',
		},
	])
);

Update an Operation

Update an existing operation.

Request

PATCH /operation/:id

Provide a partial operation object as the body of your request.

POST /graphql/system

type Mutation {
	update_operations_item(id: ID!, data: update_directus_operations_input): directus_operations
}
import { createDirectus, rest, updateOperation } from '@directus/sdk';

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

const result = await client.request(updateOperation(operation_id, partial_operation_object));

Query Parameters

Supports all global query parameters.

Request Body

A partial operation object.

Response

Returns the operation object for the updated operation.

Example

PATCH /operation/7d62f1e9-a83f-407b-84f8-1c184f014501

{
	"name": "My Updated Operation"
}

POST /graphql/system

mutation {
	update_operations_item(id: "7d62f1e9-a83f-407b-84f8-1c184f014501", data: { name: "My Updated Operation" }) {
		id
		name
	}
}
import { createDirectus, rest, updateOperation } from '@directus/sdk';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	updateOperation('4b220e51-5e2b-48b5-a988-0a6451624d0c', {
		position_x: '5',
	})
);

Update Multiple Operations

Update multiple existing operations.

PATCH /operations

{
	"keys": operation_id_array,
	"data": partial_operation_object
}

POST /graphql/system

type Mutation {
	update_operations_items(ids: [ID!]!, data: update_directus_operations_input): [directus_operations]
}
import { createDirectus, rest, updateOperations } from '@directus/sdk';

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

const result = await client.request(updateOperations(operations_id_array, partial_operations_object));

Query Parameters

Supports all global query parameters.

Request Body

keys Required
Array of primary keys of the operations you'd like to update.

data Required
Any of the operation object's properties.

Response

Returns the operation objects for the updated operations.

Example

PATCH /operations

{
	"keys": ["6a25fb7c-26a4-4dcb-a474-d47b6a203a38", "07ac467e-1900-4c62-9637-8dac2ab97f71"],
	"data": {
		"name": "Updated Operations"
	}
}

POST /graphql/system

mutation {
	update_operations_items(
		ids: ["6a25fb7c-26a4-4dcb-a474-d47b6a203a38", "07ac467e-1900-4c62-9637-8dac2ab97f71"]
		data: { name: "Updated Operations" }
	) {
		id
		name
		key
	}
}
import { createDirectus, rest, updateOperations } from '@directus/sdk';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	updateOperations(['263b18e6-7297-4a9f-af88-15af7317d4ef', '4b220e51-5e2b-48b5-a988-0a6451624d0c'], {
		position_y: '50',
	})
);

Delete an Operation

Delete an existing operation.

Request

DELETE /operations/:id

POST /graphql/system

type Mutation {
	delete_operations_item(id: ID!): delete_one
}
import { createDirectus, rest, deleteOperation } from '@directus/sdk';

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

const result = await client.request(deleteOperation(operation_id));

Returns

Empty body.

Example

DELETE /operations/07ac467e-1900-4c62-9637-8dac2ab97f71

mutation {
	delete_operations_item(id: "07ac467e-1900-4c62-9637-8dac2ab97f71") {
		id
	}
}
import { createDirectus, rest, deleteOperation } from '@directus/sdk';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(deleteOperation('263b18e6-7297-4a9f-af88-15af7317d4ef'));

Delete Multiple Operations

Delete multiple existing operations.

Request

DELETE /operations

Provide an array of operation IDs as the body of your request.

POST /graphql/system

type Mutation {
	delete_operations_items(ids: [ID!]!): delete_many
}
import { createDirectus, rest, deleteOperations } from '@directus/sdk';

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

const result = await client.request(deleteOperations(operations_id_array));

Request Body

An array of operations primary keys

Returns

Empty body.

Example

DELETE /operations

["a791ce73-41a2-4fb7-8f67-c7ba176cc719", "4e57ab0e-f4ec-47b5-9dad-e36f08a25642", "5fe0a6f6-18ad-4bb3-94c6-2e033246c784"]

POST /graphql/system

mutation {
	delete_operations_items(
		ids: [
			"a791ce73-41a2-4fb7-8f67-c7ba176cc719"
			"4e57ab0e-f4ec-47b5-9dad-e36f08a25642"
			"5fe0a6f6-18ad-4bb3-94c6-2e033246c784"
		]
	) {
		ids
	}
}
import { createDirectus, rest, deleteOperations } from '@directus/sdk';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	deleteOperations(['263b18e6-7297-4a9f-af88-15af7317d4ef', '4b220e51-5e2b-48b5-a988-0a6451624d0c'])
);

Triggering an operation

Trigger an operation based on primary key.

Request

POST /operations/trigger/:operation_uuid

import { createDirectus, rest, triggerOperation } from '@directus/sdk';

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

const result = await client.request(triggerOperation(operation_id, webhook_payload_object));

Request Body

Payload for the operation, if needed.

Returns

Result of the operation, if any.

Example

POST /flows/trigger/202a940b-a00b-47df-b832-369c53f13122

// Payload here
import { createDirectus, rest, triggerOperation } from '@directus/sdk';

const client = createDirectus('https://directus.example.com').with(rest());

const result = await client.request(
	triggerOperation('0691f58d-ed72-40ea-81b4-81c0f1e83262', {
		// Payload
	})
);