Sorry, no results found for "".
To retrieve a collection of records, send a GET request to the /items
endpoint. The collection is paginated, so make sure to iterate over all the pages if you need every record in the collection!
The following table contains the list of all the possible arguments, along with their type, description and examples values.
Pro tip: in case of any doubts you can always inspect the network calls that the CMS interface is doing, as it's using the Content Management API as well!
For Modular Content, Structured Text and Single Block fields. If set, returns full payload for nested blocks instead of IDs
Attributes to filter records
Record (or block record) IDs to fetch, comma separated. If you use this filter, you must not use filter[type]
or filter[fields]
"c89tCUarTvGKxA37acCEWA,aCiWeOsUT3mxY0KIzUfAhw"
Model ID or api_key
to filter. If you use this filter, you must not use filter[ids]
. Comma separated values are accepted, but you must not use filter[fields]
in this case
"cat,dog"
Textual query to match. You must not use filter[ids]
. If locale
is defined, search within that locale. Otherwise environment's main locale will be used.
"foo"
Same as GraphQL API records filters: you must use square brackets to indicate nesting levels. E.g. if you wanna filter by parent record in a tree of records, you must use filter[fields][parent][eq]=<ID_VALUE>
. Use snake_case for fields names. If locale
is defined, search within that locale. Otherwise environment's main locale will be used.
{ name: { eq: "Buddy" } }
When set, only valid records are included in the results.
"true"
When filter[query]
or field[fields]
is defined, filter by this locale. Default: environment's main locale
"it"
Parameters to control offset-based pagination
The (zero-based) offset of the first entity returned in the collection (defaults to 0)
200
The maximum number of entities to return (defaults to 30, maximum is 500)
Fields used to order results. You must specify also filter[type]
with one element only to be able use this option. Format: <field_name>_(ASC|DESC)
, where <field_name>
can be either the API key of a model's field, or one of the following meta columns: id
, _updated_at
, _created_at
, _status
, _published_at
, _first_published_at
, _publication_scheduled_at
, _unpublishing_scheduled_at
, _is_valid
, position
(only for sortable models). You can pass multiple comma separated rules.
"name_DESC"
Whether you want the currently published versions (published
, default) of your records, or the latest available (current
)
"current"
Returns an array of resource objects of type item
If you don't specify any parameters, we'll simply return the first 30 records. They can be from any model in your project.
Showing the default number of results (30 records) from any model
To fetch a specific page, you can use the page
object in the query params together with its offset
and limit
parameters. They will still be from any model in your project.
To get 2 records starting from position 4, we should use: limit: 2
and offset: 3
(because record counting starts from 0)
Instead of fetching a single page at a time, sometimes you want to get all the pages together.
You can do this using the client.items.listPagedIterator()
method with an async iteration statement, which will handle pagination for you. All the details on how to use listPagedIterator()
are outlined on this page.
Note that this will return records across all your models, unless you specify a filter. Unfiltered, this is useful for fetching all the records in your project (e.g. for backup or export purposes). To filter by IDs or models, see the other examples below.
Showing all results of client.items.listPagedIterator()
, from any model
You can retrieve a list of records (or blocks) by their record IDs. They can be from the same or different models.
Showing two records from different models: dog and song. The returned record order is random, not the order of the record IDs you specified.
You can filter the records by one or more model types. You can use either the model's api_key
(that you define) or its unique ID (generated by DatoCMS). Multiple comma-separated values are accepted:
By default, the API only returns published records. Using the version
parameter, you can choose to also include drafts and updates.
version: 'current'
will return the most recent versions of the queried records. Sometimes this can be the same as the published version, but other times it could be an unpublished draft or update:
draft
means the record has been created and saved, but not yet published (or was unpublished)published
means the record has been published, and there are no later changes (i.e., the published version is the most recent version)updated
means the record was previously published, but there are new changes that have been saved and not yet published (the current version is ahead of the published version)To get only draft, updated, or published records, you can filter on this response's record.meta.status
property on the client side, after the fetch:
Within a specified model, you can further filter its records by their field values.
You must specify a single model using filter[type]
. You cannot filter by field value across multiple models at once.
Valid filters are documented at GraphQL API records filters, so please check there. However, you cannot use deep filtering on Modular Content and Structured Text fields at the moment.
locale
parameter if you are filtering by a localized field.order_by
parameter.In this example, we are filtering the model dog
by:
name in ['Buddy','Rex']
(matching Buddy
OR Rex
)breed eq 'mixed'
(matching exactly mixed
)_updated_at
) (and ordering the results by the same)You can retrieve a list of records filtered by a textual query match. It will search in block records content too. Set the nested
parameter to true
to retrieve embedded block content as well.
You can narrow your search to some models by specifying the field[type]
attribute. You can use either the model's api_key
or its unique ID. Multiple comma-separated values are accepted.
You should specify the locale
attribute, or it use the environment's default locale.
Returned records are ordered by rank.
Sometimes, you may wish to fetch a record that has embedded blocks inside Structured Text or Modular Content fields.
By default, we would return those nested blocks as references, like:
But if you add the nested: true
query parameter, we'll embed the block content inline for you.
When nested: true
, the maximum records you can request at once is limited to 30, compared to the usual 500.
import { buildClient } from "@datocms/cma-client-node";
async function run() { // Make sure the API token has access to the CMA, and is stored securely const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });
const records = await client.items.list({ filter: { ids: "FEzWmQhjQgeHsCrUtvlEMw", // Only one record, an example post }, nested: true, // But retrieve its nested block content as well });
// Instead of console.log, console.dir will fully expand nested objects // See https://nodejs.org/api/console.html#consoledirobj-options // This way, we can better see the embedded blocks in the response console.dir(records, { depth: null });}
run();
[ { id: "FEzWmQhjQgeHsCrUtvlEMw", type: "item", structured_text_field: { schema: "dast", document: { children: [ { item: { type: "item", attributes: { button_label: "Example button", button_url: "https://www.example.com", }, relationships: { item_type: { data: { id: "SkVjHJSGR5CyK16E8TfJxg", type: "item_type" }, }, }, id: "ahxSnFQEQ02K3TjttWAg-Q", }, type: "block", }, { item: { type: "item", attributes: { nested_structured_text_field: { schema: "dast", document: { children: [ { children: [ { type: "span", value: "This is a " }, { marks: ["emphasis"], type: "span", value: "nested", }, { type: "span", value: " structured text block inside the parent structured text field.", }, ], type: "paragraph", }, { item: { type: "item", attributes: { button_label: "And this is a button inside the nested structured text block", button_url: "https://www.example2.com", }, relationships: { item_type: { data: { id: "SkVjHJSGR5CyK16E8TfJxg", type: "item_type", }, }, }, id: "CGqwjPDsTHKGFy1IbC0RAQ", }, type: "block", }, ], type: "root", }, }, }, relationships: { item_type: { data: { id: "Ty4S40cbQH6_VMNnGdd9KA", type: "item_type" }, }, }, id: "AppHB06oRBm-er3oooL_LA", }, type: "block", }, ], type: "root", }, }, item_type: { id: "UVa_hHEBSeefLEUnwoQFig", type: "item_type" }, creator: { id: "104280", type: "account" }, meta: { created_at: "2024-03-13T17:01:19.243+00:00", updated_at: "2024-03-13T17:14:17.444+00:00", published_at: "2024-03-13T17:14:17.597+00:00", publication_scheduled_at: null, unpublishing_scheduled_at: null, first_published_at: "2024-03-13T17:01:19.326+00:00", is_valid: true, is_current_version_valid: true, is_published_version_valid: true, status: "published", current_version: "DLtyHZ2MTDqYMg7g5mgYEw", stage: null, }, },]