Our NodeJS datocms-client
package makes it easy to programmatically read/create/edit/destroy any kind of resource a DatoCMS project might contain.
Install the datocms-client
package in your application:
$ npm install --save-dev datocms-client
Or, if you're using Yarn as package manager:
$ yarn add datocms-client
Warning: due to historical reasons and backward compatibility, the API exposes some different naming compared to the rest of the product: Models are called Item Types, while Records are called Items. Keep that in mind!
The first step is to require the DatoCMS package, and initialize the client with the read-write API token you can find under the Admin area > API tokens section:
const { SiteClient } = require('datocms-client');const client = new SiteClient('YOUR_API_READWRITE_TOKEN');
If you need to work inside a sandbox environment, you can pass its name as second argument:
const client = new SiteClient('YOUR_API_READWRITE_TOKEN',{ environment: 'my-sandbox' },);
Our API reference has JS examples for each of the available endpoints. Here's a list of the ones you'll probably find using more often:
Interacting with records:
Managing assets:
Making schema changes: