To list all records, send a GET request to the /items
endpoint.
The following table contains the list of all the possible arguments, along with their type, description and examples values.
To filter items you can use or filter[ids]
alone or filter[type]
in combination with other type of filters.
For Modular Content fields and Structured Text fields, return full payload for nested blocks instead of IDs
IDs to fetch, comma separated
model ID to filter
textual query to match, remember to specify also filter[type]
to be able use this option
index of first record to fetch
number of records to fetch, maximum is 500 records per page
whether you want the currently published versions of your records, or the latest available
You can retrieve a list of records filtered by a set of conditions on the fields. There are different options for every field and you can combine multiple filters together.
In this example we are filtering by a single line string and by a date.
The filtering options are the same as the GraphQL API filters. So please check there all the options.
The only difference is that when using this API you should snake-case the fields instead of camel-casing as in the GraphQL API.
In case of any doubts you can always inspect the network calls that the CMS interface is doing, as it's using the public REST API and you are able to replicate the same calls.
const { SiteClient } = require("datocms-client");const client = new SiteClient("YOUR-API-TOKEN");async function getFilteredRecords() {const records = await client.items.all({filter: {type: "dog",fields: {name: {eq: "Patato",},_updated_at: {gt: "2020-04-18T00:00:00",},},},});console.log(records);}getFilteredRecords();
[{id: "4579273",name: "Gigio",picture: {uploadId: "1642386",alt: null,title: null,focalPoint: { x: 0.5, y: 0.5 },customData: {},},description: [],breed: "Labrador",age: 4,height: 50.5,dateOfBirth: "2020-04-17T17:25:00+01:00",available: true,location: { latitude: 45.0703393, longitude: 7.686864 },color: { red: 239, blue: 156, alpha: 255, green: 208 },json: '{"additionalData": "1234"}',friends: ["4572300", "4572298", "4572297", "4572180", "4572128"],updatedAt: "2020-04-20T11:06:29.130+01:00",createdAt: "2020-04-20T11:06:29.126+01:00",meta: {createdAt: "2020-04-20T11:06:29.126+01:00",updatedAt: "2020-04-20T11:06:29.130+01:00",publishedAt: "2020-04-20T11:06:29.150+01:00",firstPublishedAt: "2020-04-20T11:06:29.150+01:00",publicationScheduledAt: null,unpublishingScheduledAt: null,status: "published",isValid: true,currentVersion: "8062918",},itemType: "1234",creator: { id: "322", type: "access_token" },},];
const SiteClient = require('datocms-client').SiteClient;const client = new SiteClient('YOUR-API-TOKEN');client.items.all({nested: 'true','filter[ids]': '12,31','filter[type]': '44','filter[fields]': 'foo','page[offset]': 2,'page[limit]': 15,version: 'published'}).then((items) => {items.forEach((item) => {console.log(item);});}).catch((error) => {console.error(error);});// if you want to fetch all the pages with just one call:client.items.all({nested: 'true','filter[ids]': '12,31','filter[type]': '44','filter[fields]': 'foo',version: 'published'}, {allPages: true}).then((items) => {items.forEach((item) => {console.log(item);});})
> node example.js{"id": "4235","title": "My first blog post!","content": "Lorem ipsum dolor sit amet...","category": "24","image": {"uploadId": "1235","alt": "Alt text","title": "Image title","customData": {}},"meta": {"created_at": "2020-04-21T07:57:11.124Z","updated_at": "2020-04-21T07:57:11.124Z","published_at": "2020-04-21T07:57:11.124Z","first_published_at": "2020-04-21T07:57:11.124Z","publication_scheduled_at": "2020-04-21T07:57:11.124Z","unpublishing_scheduled_at": "2020-04-21T07:57:11.124Z","status": "draft","is_valid": true,"current_version": "4234"},"itemType": "44","creator": "312"}