Registry / marketing / mailerlite-api-v2-node

mailerlite-api-v2-node

JSON →
library1.2.0jsnpmunverified

Node.js SDK for MailerLite API v2, version 1.2.0. It is a thin wrapper around Axios providing authentication, automatic camelCase conversion for request/response, TypeScript type definitions, and shorthand methods for MailerLite endpoints (account, campaigns, groups, segments, subscribers, webhooks, etc.). The library resolves API responses to body only (not full Axios response). It uses a default base URL of https://api.mailerlite.com/api/v2/ and offers options to override Axios config and headers. Release cadence is low; last release was over 2 years ago. Differentiators: built-in camelCase conversion and TypeScript support, unlike simpler wrappers.

npm install mailerlite-api-v2-node
INSTALL
IMPORT
SIG · MAILERLITE-API-V2-
M
mailerlite-api-v2-node
marketingjavascriptv1.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import MailerLite from 'mailerlite-api-v2-node'
const MailerLite = require('mailerlite-api-v2-node')
Only default export is available; the CommonJS require must include .default or use ESM import. Since v1.0, the package uses .default export.
MailerLite
import MailerLite from 'mailerlite-api-v2-node'
import { MailerLite } from 'mailerlite-api-v2-node'
Named import does not exist; use default import. CommonJS: const MailerLite = require('mailerlite-api-v2-node').default
MailerLite (as constructor)
const mailerLite = new MailerLite(apiKey)
const mailerLite = MailerLite(apiKey)
Though both work, the constructor pattern is conventional; calling MailerLite() without new also works but may confuse TypeScript.

Initializes MailerLite client with API key, fetches account, retrieves recent subscribers, and creates a group.

import MailerLite from 'mailerlite-api-v2-node'; const mailerLite = new MailerLite(process.env.MAILERLITE_API_KEY ?? ''); async function main() { try { const account = await mailerLite.getAccount(); console.log('Account email:', account.email); const subscribers = await mailerLite.getSubscribers({ limit: 10 }); console.log('Subscribers:', subscribers); const group = await mailerLite.createGroup({ name: 'Test Group' }); console.log('Group created:', group.id); } catch (error) { console.error('Error:', error); } } main();
Debug
Known issues
gotchaThe library uses .default export; CommonJS require must use require('mailerlite-api-v2-node').default instead of direct require.
fix
Use const MailerLite = require('mailerlite-api-v2-node').default
affects: >=1.0.0
deprecatedMailerLite API v2 is deprecated in favor of API v3 (as of 2022). The library has not been updated for v3.
fix
Consider migrating to MailerLite API v3 or using a different SDK (e.g., @mailerlite/mailerlite-nodejs).
affects: all
gotchaAPI responses are resolved to body only (not full Axios response). Cannot access status codes or headers from the promise resolution.
fix
If you need full response, use the raw methods (e.g., getCampaignsRaw) which return the full Axios response.
affects: all
gotchaCamelCase conversion can cause unexpected behavior with nested objects or custom fields. The conversion may incorrectly modify keys that are not in snake_case.
fix
Disable camelCase conversion by passing { useCaseConverter: false } in options.
affects: all
Errors
Common errors & fixes
const mailerLite = require('mailerlite-api-v2-node'); mailerLite.getAccount is not a function
CommonJS require returns the module, not the default export
fix
Use require('mailerlite-api-v2-node').default
import MailerLite from 'mailerlite-api-v2-node'; TypeError: MailerLite is not a constructor
Using the imported default as a class but without 'new' or the module is not returning a class
fix
Use new MailerLite(apiKey) explicitly
TypeError: Cannot read property 'email' of undefined
API response is not the body but the full Axios response (unlikely) or the method name is wrong
fix
Ensure the method exists (list of methods in README) and that you are not using a raw method like getAccountRaw which returns the full response
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
axiosrequiredHTTP client for all API requests
camelcase-keysrequiredConverts response keys to camelCase
decamelize-keysrequiredConverts request keys to snake_case
Agent activity
27 hits · last 30 days
node
20
OpenAI (training)
1
Resources
mailerlite-api-v2-node — npm install mailerlite-api-v2-node · libregistry