The Node SDK provides a comprehensive TypeScript library for easily integrating with the Mambo API. This client library simplifies development by handling authentication, request formatting, and response parsing, allowing you to focus on your application logic. Built with TypeScript and zero production dependencies, the SDK works seamlessly across Node.js, Bun, Deno, browsers, and edge runtimes.
To connect to the Mambo API, use one of the service classes provided through the client instance. See the code samples below for implementation examples.
The Mambo Node SDK has zero production dependencies, making it lightweight and easy to integrate into any project. All required functionality is built directly into the SDK.
import { MamboClient } from '@mambo/sdk';
// Browser usage - authentication handled by backend/cookies
const client = new MamboClient({
baseUrl: 'https://api.mambo.io'
});
await client.activities.createAsync({ siteUrl: 'acmeinc' }, data);
import { MamboClient } from '@mambo/sdk';
// Browser usage - authentication handled by backend/cookies
const client = new MamboClient({
baseUrl: 'https://api.mambo.io'
});
await client.activities.createAsync({ siteUrl: 'acmeinc' }, data);
warning
Never include OAuth credentials in browser code. Browser applications should use a backend proxy for authentication or rely on session cookies. See the Browser vs Node.js section for details.
The SDK automatically detects and adapts to different JavaScript runtimes:
Bun
Deno
Cloudflare
Vercel
import { MamboClient } from './mambo-sdk-node/esm';
const client = new MamboClient('public_key', 'private_key');
// Bun automatically uses the Fetch API
await client.activities.createAsync({ siteUrl: 'acmeinc' }, data);
import { MamboClient } from './mambo-sdk-node/esm/index.js';
const client = new MamboClient('public_key', 'private_key');
// Deno automatically uses the Fetch API
await client.activities.createAsync({ siteUrl: 'acmeinc' }, data);
import { MamboClient } from '@mambo/sdk';
export default {
async fetch(request: Request): Promise<Response> {
const client = new MamboClient('public_key', 'private_key');
const result = await client.activities.createAsync(
{ siteUrl: 'acmeinc' },
data
);
return new Response(JSON.stringify(result));
}
};
import { MamboClient } from '@mambo/sdk';
import { NextRequest, NextResponse } from 'next/server';
export const config = {
runtime: 'edge'
};
export default async function handler(req: NextRequest) {
const client = new MamboClient('public_key', 'private_key');
const result = await client.activities.createAsync(
{ siteUrl: 'acmeinc' },
data
);
return NextResponse.json(result);
}
Use parameter objects to provide path and query parameters to endpoint methods. TypeScript provides full type safety and autocomplete for all parameters.
Use the request options object to provide configuration on a per-request basis. This object can be used to provide idempotency keys, custom headers, or request-specific timeouts.
In server-side Node.js applications, you provide OAuth credentials directly to the SDK. The SDK handles token management automatically.
Node
import { MamboClient } from '@mambo/sdk';
// Server-side: OAuth credentials are safe
const client = new MamboClient('public_key', 'private_key');
await client.activities.createAsync({ siteUrl: 'acmeinc' }, data);
Browser (No credentials):
Browser applications must never include OAuth credentials in client-side code. Instead, use one of these patterns:
Backend Proxy: Route API calls through your backend server
Session Cookies: Let your backend set session cookies that authenticate requests
For a ready-to-run backend proxy that holds the keys and forwards requests, see the Backend proxy guide.
Browser (Backend Proxy)
Browser (Custom Authenticator)
import { MamboClient } from '@mambo/sdk';
// Browser: No credentials - authentication via backend/cookies
const client = new MamboClient({
baseUrl: 'https://your-backend.com/api/mambo'
});
// Requests go through your backend proxy
await client.activities.createAsync({ siteUrl: 'acmeinc' }, data);
import { MamboClient, NoAuthAuthenticator } from '@mambo/sdk';
// Explicitly use NoAuthAuthenticator
const client = new MamboClient({
baseUrl: 'https://api.mambo.io',
authenticator: new NoAuthAuthenticator()
});
// Your backend must set authentication cookies
await client.activities.createAsync({ siteUrl: 'acmeinc' }, data);
Security Warning
Never expose OAuth credentials in browser code. Anyone with access to your client-side JavaScript can extract and misuse your credentials. Always use a backend proxy or session-based authentication for browser applications.
The SDK automatically selects the appropriate HTTP client:
Node.js: Uses NodeHttpClient with native http/https modules
Browser/Deno/Bun/Edge: Uses FetchHttpClient with the Fetch API
You can also provide a custom HTTP client:
TypeScript
import { MamboClient, FetchHttpClient } from '@mambo/sdk';
// Force use of Fetch client in Node.js (if needed)
const client = new MamboClient({
clientId: 'public_key',
clientSecret: 'private_key',
httpClient: new FetchHttpClient()
});
Every failure raised by the SDK rejects the promise returned by the service method, so errors are caught with a standard try/catch around await. The SDK exports the error classes below, all of which extend MamboError:
Error
Raised when
MamboApiError
The API returned an error response. Extends MamboError.
AuthenticationError
The request was rejected with a 401 or 403. Extends MamboApiError.
IdempotencyError
The idempotency key was invalid, already used, or its request is still in progress. Extends MamboApiError.
OAuthError
The OAuth token could not be obtained. Extends MamboError.
ApiConnectionError
The API could not be reached. Extends MamboError.
TimeoutError
The request did not complete within the configured timeout. Extends MamboError.
ConfigurationError
The client configuration is invalid. Thrown by the MamboClient constructor.
Because JavaScript has a single catch block, you discriminate between them with instanceof, ordering the checks from most to least specific:
Node
import { AuthenticationError, MamboApiError, MamboError } from '@mambo/sdk';
try {
const wallets = await client.users.points.getPointWallets({
siteUrl: 'acmeinc',
uuid: 'user_uuid'
});
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Check your API keys');
} else if (error instanceof MamboApiError) {
console.error(error.getDetailedMessage(), error.status, error.requestId);
} else if (error instanceof MamboError) {
console.error(error.toJSON());
} else {
throw error;
}
}
You do not need to handle expired access tokens. When the API rejects a token, the SDK obtains a new one and replays the request transparently.
See Errors for the full list of error types returned by the API.
If you experience connection timeouts, you can increase the timeout when initialising the client. The Node SDK applies a single timeout to the whole request, expressed in milliseconds, which defaults to 30 seconds and cannot exceed 5 minutes:
The SDK does not retry failed requests by default. Set maxRetries to retry connection failures, timeouts, and the responses that are safe to replay (408, 409, 429 and 5xx):
Node
const client = new MamboClient({
clientId: 'public_key',
clientSecret: 'private_key',
maxRetries: 3 // retried with an exponential backoff
});