Show examples in:
Javascript HTTP
Endpoint info
Available examples

Content Management API > Model filter

Create a new filter

Body parameters

id string Optional

RFC 4122 UUID of filter expressed in URL-safe base64 format

Example: "FF-P5of6Qp-DD2w0xoaa6Q"
name string Required

The name of the filter

Example: "Draft posts"
filter object Optional

The actual filter. It follows the form of the filter query parameter of the List all records endpoint.

Example: { query: "foo bar", fields: { _status: { eq: "draft" }, title: { matches: { pattern: "qux", case_sensitive: "false", regexp: "false" }, }, }, }
columns Optional

The columns to show with this filter

Type: Array<object>, null
Example: [ { name: "_preview", width: 0.6 }, { name: "slug", width: 0.1 }, { name: "_status", width: 0.1 }, { name: "_updated_at", width: 0.2 }, ]
name string Required

Can be either the API key of a model's field, or one of the following meta columns: id, _preview, _updated_at, _created_at, _creator, _status, _published_at, _first_published_at, _publication_scheduled_at, _unpublishing_scheduled_at, position (only for sortable models), `_stage (only for models associated with a workflow).

width number Required

The percentage width for the column (float, from 0 to 1.0)

order_by string, null Optional

The ordering to apply with this filter, or null for the default model ordering. It follows the form of the order_by query parameter of the List all records endpoint.

Example: "_updated_at_ASC"
shared boolean Optional

Whether it's a shared filter or not

item_type Required

Model associated with the filter

Returns

Returns a resource object of type item_type_filter

Examples

1
import { buildClient } from "@datocms/cma-client-node";
2
3
async function run() {
4
const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });
5
6
const itemTypeFilter = await client.itemTypeFilters.create({
7
name: "Draft posts",
8
item_type: { type: "item_type", id: "DxMaW10UQiCmZcuuA-IkkA" },
9
});
10
11
// Check the 'Returned output' tab for the result ☝️
12
console.log(itemTypeFilter);
13
}
14
15
run();
1
{
2
id: "FF-P5of6Qp-DD2w0xoaa6Q",
3
name: "Draft posts",
4
filter: {
5
query: "foo bar",
6
fields: {
7
_status: { eq: "draft" },
8
title: {
9
matches: { pattern: "qux", case_sensitive: "false", regexp: "false" },
10
},
11
},
12
},
13
columns: [
14
{ name: "_preview", width: 0.6 },
15
{ name: "slug", width: 0.1 },
16
{ name: "_status", width: 0.1 },
17
{ name: "_updated_at", width: 0.2 },
18
],
19
order_by: "_updated_at_ASC",
20
shared: true,
21
item_type: { type: "item_type", id: "DxMaW10UQiCmZcuuA-IkkA" },
22
}