Mixmax API Client
The `mixmax-api` library is a Node.js wrapper that provides a programmatic interface for interacting with the Mixmax platform. It simplifies common operations such as managing email sequences, adding recipients, and leveraging features like polls, Q&A, and sidebars within Mixmax. The current stable version is 1.5.0, with the last release dating back to December 2020. This indicates a slow or paused release cadence, meaning new Mixmax API features might not be immediately supported by this library. Its primary differentiator is offering a convenient JavaScript interface over the raw Mixmax REST API, which is designed for lightweight, real-time interactions and has a rate limit of 120 requests per minute per user and IP address.
Common errors
-
Error: Request failed with status code 401
cause Invalid or missing Mixmax API key provided during client initialization. The API token might be incorrect, expired, or have insufficient permissions.fixVerify that your `MIXMAX_API_KEY` is correct and active. Ensure it's retrieved from your Mixmax settings (Settings > Integrations > API Token) and passed correctly to the `MixmaxAPI` constructor. -
Error: Request failed with status code 404 - Sequence not found
cause The provided sequence ID does not exist, or the authenticated user does not have access to it.fixDouble-check the `sequenceID` used in your code against your Mixmax dashboard. Ensure the API key corresponds to a Mixmax account that has permission to access that specific sequence. -
Error: Request failed with status code 429 - Too Many Requests
cause Your application has exceeded the Mixmax API rate limits (120 requests per minute per user and IP address).fixImplement rate limiting on your client-side application or use a retry-with-backoff strategy to handle `429` responses. Respect the `Retry-After` header if provided in the API response. -
TypeError: api.sequences.sequence is not a function
cause This error typically occurs if the `api` object was not correctly initialized with a `MixmaxAPI` instance, or if there's a typo in `sequences` or `sequence`. It could also indicate a fundamental change in the library's API if using an incompatible version.fixEnsure `const api = new MixmaxAPI(apiKey);` executed successfully and `apiKey` was valid. Verify the correct casing and property names (`sequences`, `sequence`). If updating, check the changelog for breaking changes related to the client's structure.
Warnings
- breaking Version 1.3.0 included a fix to 'update HTTP calls to use new format'. While described as a fix, this indicates changes to the underlying Mixmax API or how the wrapper interacts with it. Older versions might experience connectivity issues or incorrect behavior if the Mixmax API has since diverged significantly.
- gotcha The package has not been updated since December 2020. This means it may not support newer features of the Mixmax platform or gracefully handle recent changes to the Mixmax API. The official Mixmax API documentation continues to be updated, suggesting potential discrepancies.
- gotcha Mixmax API requests are subject to rate limits (120 requests per minute per user and IP address). Exceeding these limits will result in errors.
- gotcha Authentication requires an API key, which must be obtained from your Mixmax settings page. Improper handling or exposure of this key can lead to unauthorized access to your Mixmax data.
Install
-
npm install mixmax-api -
yarn add mixmax-api -
pnpm add mixmax-api
Imports
- MixmaxAPI
import MixmaxAPI from 'mixmax-api';
const MixmaxAPI = require('mixmax-api'); - MixmaxAPI (ESM approximation)
import { MixmaxAPI } from 'mixmax-api';import MixmaxAPI from 'mixmax-api'; // May require Node.js `--experimental-json-modules` or build step
Quickstart
const MixmaxAPI = require('mixmax-api');
// IMPORTANT: Replace with your actual Mixmax API key from settings.
// You can retrieve this key from your Mixmax settings page (Settings -> Integrations -> API).
// Do NOT hardcode in production; use environment variables.
const apiKey = process.env.MIXMAX_API_KEY ?? 'YOUR_SUPER_SECRET_MIXMAX_API_KEY';
if (!apiKey || apiKey === 'YOUR_SUPER_SECRET_MIXMAX_API_KEY') {
console.error('Mixmax API Key is missing. Please set the MIXMAX_API_KEY environment variable or replace the placeholder.');
process.exit(1);
}
const api = new MixmaxAPI(apiKey);
async function addRecipientToSequence() {
// Replace with an actual sequence ID from your Mixmax account
const sequenceID = 'your-mixmax-sequence-id';
const recipientEmail = 'test-recipient@example.com';
try {
const sequence = api.sequences.sequence(sequenceID);
const results = await sequence.addRecipients([
{
email: recipientEmail,
variables: {
firstName: 'Test',
lastName: 'User'
}
}
]);
console.log('Successfully added recipient to sequence:', results);
} catch (error) {
console.error('Error adding recipient to sequence:', error.message);
if (error.response && error.response.data) {
console.error('API Error Details:', error.response.data);
}
}
}
addRecipientToSequence();