Node.js

Introduction

The Mangopay Node.js SDK makes working with the Mangopay API easier in a Node.js environment.

The SDK package is available on npm: mangopay4-nodejs-sdk

Caution – Use only the mangopay4 package (late Nov 2025)

Please ensure you use only the package with mangopay4 in the name (this is the package name and has no connection with the SDK version number).

Any other package must not be used. You need to update your package manually.

Since November 25, 2025, Mangopay’s official SDKs are no longer accessible on GitHub (with the exception of PHP for publication reasons).

Prerequisites

To run the Mangopay Node.js SDK, you’ll need:

  • A ClientId and an API key – if you don’t have these, contact Sales to get access to the Mangopay Dashboard
  • Node.js installed (v.14 and higher)
  • npm package manager installed

Note - Mangopay SDK compatibility

The Node.js SDK is only compatible with the v2.01 version of the Mangopay API.

Getting started

  1. Install the SDK
1npm install mangopay4-nodejs-sdk --save
  1. Initialize the SDK
1const mangopay = require('mangopay4-nodejs-sdk');
2
3const paymentApi = new mangopay({
4 clientId: 'your-mangopay-client-id',
5 clientApiKey: 'your-mangopay-api-key',
6 baseUrl: 'https://api.sandbox.mangopay.com'
7});

The configuration object of the SDK supports all the following properties:

KeyTypeDefault valueDescription
clientIdstringnullYour Mangopay ClientId – can be found in the Dashboard.
clientApiKeystringnullYour Mangopay API key – can be found in the Dashboard.
baseUrlstringhttp://api.sandbox.mangopay.com/The API sandbox URL. Set to the sandbox environment by default. To enable production environment, set it to http://api.mangopay.com/
debugModebooleanfalseActivates the debug mode. Recommended only in Sandbox.
logClassfunction() {console.log(arguments)}function() {console.log(arguments)}
connectionTimeoutinteger30000Set the time to wait (in milliseconds) while trying to establish a connection before terminating the attempt and generating an error.
responseTimeoutinteger80000Set response timeout limit (in milliseconds).
apiVersionstringv2.01The API version.
errorHandlernullfunction(options, err) {console.error(options, err)}Set a custom error handler.

SDK usage

All endpoints are documented with the related Node.js SDK method throughout the Mangopay documentation. The code examples provided should be adjusted for your usage.

TypeScript

The SDK is compatible with TypeScript and provides a set of predefined models. They are available in the /lib/models/ folder.

Using callbacks instead of promises

Across the Mangopay endpoint documentation, the usage of the SDK is documented with promises. If you prefer callbacks, here is an example on how to use them:

1const mangopayInstance = require('mangopay4-nodejs-sdk')
2const mangopay = new mangopayInstance({
3 clientId: 'your-client-id',
4 clientApiKey: 'your-api-key',
5})
6
7let user = {
8 Id: '171602348',
9}
10
11mangopay.Users.get(user.Id, function(data, response, err){
12 console.log(data)
13 console.log(response)
14 console.log(err)
15})

Pagination and filtering

For endpoints that support pagination and filtering, you can use options.parameters to specify these options:

1const mangopayInstance = require('mangopay4-nodejs-sdk')
2const mangopay = new mangopayInstance({
3 clientId: 'your-client-id',
4 clientApiKey: 'your-api-key',
5})
6
7let parameters = {
8 // Options for pagination
9 per_page: 2,
10 page: 2,
11
12 // Options for Filters
13 BeforeDate: 1683129820,
14 AfterDate: 1682957020,
15 // Nature: REGULAR,
16 // Status: FAILED,
17 // Type: TRANSFER,
18};
19
20const indexEvents = async () => {
21 return await mangopay.Events.getAll({ parameters: parameters })
22 .then((response) => {
23 console.info(response)
24 return response;
25 })
26 .catch((err) => {
27 console.log(err)
28 return false;
29 });
30};
31
32indexEvents()

Accessing response headers

For reading the server response headers, you can use resolveWithFullResponse. This is useful to access information about the pagination or rate limiting.

1const mangopayInstance = require('mangopay4-nodejs-sdk')
2const mangopay = new mangopayInstance({
3 clientId: 'your-client-id',
4 clientApiKey: 'your-api-key',
5})
6
7const indexEvents = async () => {
8 return await mangopay.Events.getAll({ resolveWithFullResponse: true })
9 .then((response) => {
10 console.info(response.headers['x-number-of-pages'])
11 return response
12 })
13 .catch((err) => {
14 console.log(err)
15 return false
16 });
17};
18
19indexEvents()

Error handling

The SDK provides a default errorHandler in the configuration that prints any HTTP errors returned by the API to console. You can overwrite this with your own logic for global exception handling.

For a given function, you can use a .catch(error) to define specific logic, for example:

1api.Recipients.validate(recipient, userId).then(function (data) {
2 done();
3})
4 .catch(function (error) {
5 errorResult = error;
6 // your custom logic
7 });