Nimbu Developer Docs

Objects & Channels

Create, fetch, update, delete, and serialize Nimbu objects and channel entries.

Nimbu.Object is the base class for channel entries and most SDK resources.

Create

const article = new Nimbu.Object('articles', {
  title: 'New article',
  status: 'draft'
});

await article.save();

You can also use subclasses when a file works with one channel often:

const Article = Nimbu.Object.extend('articles');

const article = new Article({
  title: 'New article'
});

Read

const article = await new Nimbu.Query('articles').get(articleId);

console.log(article.id);
console.log(article.get('title'));

To fetch an object you already have an id for:

const article = new Nimbu.Object('articles', { id: articleId });
await article.fetch();

Update

article.set('status', 'published');
article.set({
  published_at: new Date(),
  reviewed: true
});

await article.save();

save() also accepts attributes directly:

await article.save({
  status: 'archived'
});

Delete

const article = await new Nimbu.Query('articles').get(articleId);
await article.destroy();

Use wait: true when you need the object state to update after the API confirms deletion:

await article.destroy({ wait: true });

Attributes

Common helpers:

article.get('title');
article.has('title');
article.unset('subtitle');
article.increment('views', 1);

article.keys();
article.pick('title', 'status');
article.omit('body');
article.toJSON();

createdAt, updatedAt, and shortId are convenience accessors:

article.createdAt;
article.updatedAt;
article.shortId;

Change Tracking

The SDK tracks local changes before save:

article.set('status', 'published');

if (article.hasChanged('status')) {
  await article.save();
}

Useful helpers:

article.changedAttributes();
article.previous('status');
article.previousAttributes();

Include Relations On Fetch

const article = new Nimbu.Object('articles', { id: articleId });
await article.fetchWithInclude(['author', 'comments.author']);

Equivalent:

await article.fetch({
  include: ['author', 'comments.author']
});

Request Options

Most object reads and writes accept these options:

OptionUse
useACLRespect channel/object ACLs for the request.
forceChannelTreat reserved names like products as custom channels.
localeSave localized content for a specific locale.
sessionTokenAct on behalf of a customer session.
cascadeSaveSave unsaved child objects before saving the parent.

Example:

await article.save(
  { title: 'Nederlandse titel' },
  { locale: 'nl', useACL: true }
);

ACLs

const acl = article.getACL() || new Nimbu.ACL();

acl.setPublicReadAccess(true);
acl.setLoggedInUpdateAccess(false);

article.setACL(acl);
await article.save();

On this page