* 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>
8.9 KiB
description, readTime, pageClass
| description | readTime | pageClass |
|---|---|---|
| REST and GraphQL API documentation on the Activity collection in Directus. | 4 min read | page-reference |
Activity
All events within Directus are tracked and stored in the activities collection. This gives you full accountability over everything that happens. Learn more about Activity.
The Activity Object
action string
Action that was performed.
collection string
Collection identifier in which the item resides.
comment string
User comment. This will store the comments that show up in the right sidebar of the item edit page in the admin app.
id integer
Unique identifier for the object.
ip string
The IP address of the user at the time the action took place.
item string
Unique identifier for the item the action applied to. This is always a string, even for integer primary keys.
timestamp string
When the action happened.
user many-to-one
The user who performed this action. Many-to-one to users.
user_agent string
User agent string of the browser the user used when the action took place.
revisions one-to-many
Any changes that were made in this activity. One-to-many to revisions.
{
"action": "create",
"collection": "articles",
"comment": null,
"id": 5,
"ip": "139.178.128.0",
"item": "1",
"timestamp": "2021-02-02T12:50:26-05:00",
"user": "2d321940-69f5-445f-be6b-c773fa58a820",
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Safari/605.1.15",
"revisions": [4]
}
List Activity Actions
Returns a list of activity actions.
Request
GET /activity
SEARCH /activity
If using SEARCH you can provide a query object as the body of your request.
POST /graphql/system
type Query {
activity: [directus_activity]
}
import { createDirectus, rest, readActivities } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(readActivities(query_object));
Query Parameters
Supports all global query parameters.
Returns
An array of up to limit activity objects. If no items are available, data will be an empty array.
Example
GET /activity
SEARCH /activity
query {
activity {
# ...
}
}
import { createDirectus, rest, readActivities } from '@directus/sdk';
const client = createDirectus('https://directus.example.com').with(rest());
const result = await client.request(
readActivities({
fields: ['*'],
})
);
Retrieve Activity Action
Returns a single activity action by primary key.
Request
GET /activity/:id
POST /graphql/system
type Query {
activity_by_id(id: ID!): directus_activity
}
import { createDirectus, rest, readActivity } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(readActivity(activity_id, query_object));
Query Parameters
Supports all global query parameters.
Response
Returns an activity object if a valid identifier was provided.
Example
GET /activity/15
POST /graphql/system
query {
activity_by_id(id: 15) {
# ...
}
}
import { createDirectus, rest, readActivity } from '@directus/sdk';
const client = createDirectus('https://directus.example.com').with(rest());
const result = await client.request(
readActivity('53281', {
fields: ['*'],
})
);
Create a Comment
Creates a new comment on a given item.
Request
POST /activity/comment
{
"collection": collection_name,
"item": item_id,
"comment": comment_content
}
POST /graphql/system
type Mutation {
create_comment(collection: String!, item: ID!, comment: String!): directus_activity
}
import { createDirectus, rest, createComment } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(
createComment({
collection: collection_name,
item: item_id,
comment: comment_content,
})
);
Request Body
collection Required
Collection in which the item resides.
item Required
Primary Key of the item to comment on.
comment Required
The comment content. Supports Markdown.
Response
Returns the activity object of the created comment.
Example
POST /activity/comment
{
"collection": "pages",
"item": 3,
"comment": "Hello World"
}
POST /graphql/system
mutation {
create_comment(collection: "pages", item: 3, comment: "Hello World") {
# ...
}
}
import { createDirectus, rest, createComment } from '@directus/sdk';
const client = createDirectus('https://directus.example.com').with(rest());
const result = await client.request(
createComment({
collection: 'articles',
item: '18',
comment: 'This is the wrong article to publish!',
})
);
Update a Comment
Updates an existing comment by activity action primary key.
Response
PATCH /activity/comment/:id
{
"comment": comment_content
}
POST /graphql/system
type Mutation {
delete_comment(id: ID): delete_one
}
import { createDirectus, rest, updateComment } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(
updateComment(comment_id, {
comment: comment_content,
})
);
Request Body
comment Required
The updated comment content. Supports Markdown.
Response
Returns the activity object of the created comment.
Example
PATCH /activity/comment/15
{
"comment": "Hello World!!"
}
POST /graphql/system
mutation {
update_comment(id: 3, comment: "Hello World") {
# ...
}
}
import { createDirectus } from '@directus/sdk';
import { rest, updateComment } from '@directus/sdk/rest';
const client = createDirectus('https://directus.example.com').with(rest());
const result = await client.request(
updateComment('53727', {
comment: 'Great work!',
})
);
Delete a Comment
Deletes a comment.
Request
DELETE /activity/comment/:id
POST /graphql/system
type Mutation {
delete_comment(id: ID): delete_one
}
import { createDirectus, rest, deleteComment } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(deleteComment(comment_id));
Example
DELETE /activity/comment/15
mutation {
delete_comment(id: 3) {
id
}
}
import { createDirectus } from '@directus/sdk';
import { rest, deleteComment } from '@directus/sdk/rest';
const client = createDirectus('https://directus.example.com').with(rest());
const result = await client.request(deleteComment('53727'));