[!WARNING]
This branch contains the code for Chargebee Node.js SDK v2 which is deprecated. v2 will continue to receive updates till September 30, 2025. If you are using v2, we request you to upgrade to v3 by following this migration guide before September 30, 2025.
Chargebee Node.js Client Library

This is the node.js library for integrating with Chargebee. Sign up for a Chargebee account here.
Note
If you’re using API V1, head to chargebee-v1 branch.
Requirements
Node 0.6 or higher.
Installation
Install the latest version of the library with:
npm install chargebee
yarn add chargebee
pnpm install chargebee
Usage
The package needs to be configured with your site's API key, which is available under Configure Chargebee Section. Refer here for more details.
The full documentation can be found on the Chargebee API Docs: https://apidocs.chargebee.com/docs/api?lang=node
const chargebee = require('chargebee');
chargebee.configure({
site: '<YOUR_SITE_NAME>',
api_key: '<YOUR_API_KEY>',
});
Or using ES modules,
import chargebee from 'chargebee';
chargebee.configure({
site: '<YOUR_SITE_NAME>',
api_key: '<YOUR_API_KEY>',
});
Using Async / Await
try {
const result = await chargebee.customer
.create({
email: 'john@test.com',
})
.request();
} catch (err) {
}
Using Promises
chargebee.customer
.create({
email: 'john@test.com',
})
.request()
.then((result) => {
})
.catch((err) => {
});
Using callbacks
chargebee.customer
.create({
email: 'john@test.com',
})
.request(function (error, result) {
if (error) {
} else {
}
});
Usage with TypeScript
You can import the types as shown below.
import chargebee, { Customer } from 'chargebee';
chargebee.configure({
site: '<YOUR_SITE_NAME>',
api_key: '<YOUR_API_KEY>',
});
const createCustomer = async () => {
const inputParams: Customer.CreateInputParam = {
email: 'john@test.com',
first_name: 'John',
last_name: 'Doe',
};
const { customer } = await chargebee.customer.create(inputParams).request();
console.log(customer);
};
createCustomer();
Using filters in the List API
For pagination: offset
is the parameter that is being used. The value used for this parameter must be the value returned for next_offset
parameter in the previous API call.
const fetchCustomers = async (offset) => {
const result = await chargebee.customer.list({
limit: 2,
offset: offset,
first_name: { is: 'John' },
}).request();
return {
customers: result.list.map((obj) => obj.customer),
next_offset: result.next_offset,
};
};
const getCustomers = async () => {
const { customers, next_offset } = await fetchCustomers();
console.log('Offset:', next_offset);
await fetchCustomers(next_offset);
};
getCustomers().catch((err) => {
console.log(err);
});
Using custom headers and custom fields:
const result = await chargebee.customer
.create({ email: 'john@test.com', cf_host_url: 'http://xyz.com' })
.headers({
'chargebee-event-email': 'all-disabled',
'chargebee-request-origin-ip': '192.168.1.2',
})
.setIdempotencyKey("safeKey")
.request();
const customer = result.customer;
console.log(customer.cf_host_url);
Creating an idempotent request
Idempotency keys are passed along with request headers to allow a safe retry of POST requests.
const result = await chargebee.customer
.create({ email: 'john@test.com' })
.setIdempotencyKey("safeKey")
.request();
const customer = result.customer;
const headers = result.headers;
const isIdempotencyReplayed = result.isIdempotencyReplayed;
OR
chargebee.customer.create({ email: 'john@test.com', cf_host_url: 'http://xyz.com' })
.setIdempotencyKey("safeKey")
.request(function(error,result) {
if(error){
}else{
const customer = result.customer;
const headers = result.headers;
const isIdempotencyReplayed = result.isIdempotencyReplayed;
}
});
Passing API Keys at request level
const newCust = await chargebee.customer.create({
email: 'john@test.com',
first_name: 'John',
last_name: 'Doe'
}).request({
site: '<YOUR_SITE_NAME>',
api_key: '<YOUR_API_KEY>',
});
Processing Webhooks - API Version Check
An attribute, api_version, is added to the Event resource, which indicates the API version based on which the event content is structured. In your webhook servers, ensure this _api_version* is the same as the API version used by your webhook server's client library.
License
See the LICENSE file.