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.js
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
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()
});