Direct API & Cloud Functions
Most data work should use Nimbu.Object and Nimbu.Query. Use Nimbu.API when you need an endpoint that does not map cleanly to SDK objects.
Direct API Requests
js
const result = await Nimbu.API.patch('/customers/customer-id', {
firstname: 'Ada'
});Methods:
js
Nimbu.API.get(path, options);
Nimbu.API.post(path, body, options);
Nimbu.API.put(path, body, options);
Nimbu.API.patch(path, body, options);
Nimbu.API.delete(path, options);
Nimbu.API.request(method, path, body, options);The convenience helpers resolve with the response body.
When To Use Nimbu.API
Use direct API helpers for:
- endpoints not represented by a class
- partial system-resource updates where the SDK object shape is inconvenient
- narrow integration calls where a plain body is clearer than constructing objects
Prefer SDK objects for:
- channel entries
- relation, file, gallery, select, and ACL mutations
- code that benefits from
get,set,save, andtoJSON
Cloud Functions
Call a Cloud Function from browser, theme, external code, or other Cloud Code:
js
const shipping = await Nimbu.Cloud.run('calculateShipping', {
country: 'BE',
weight: 2.5
});Only pass JSON-serializable data. Do not pass Nimbu.Object instances as function params.
js
await Nimbu.Cloud.run('syncArticle', {
articleId: article.id
});Fetch the object inside the Cloud Function:
js
Nimbu.Cloud.define('syncArticle', async (request, response) => {
const article = await new Nimbu.Query('articles').get(request.params.articleId);
await syncArticle(article);
response.success({ ok: true });
});Error Handling
js
try {
await Nimbu.Cloud.run('syncArticle', { articleId });
} catch (error) {
console.error(error.message);
}API errors reject as Nimbu.Error when the server returns a Nimbu error payload.