Chargebee uses HTTP Basic authentication for API calls. The username is your API key while the password is empty. You can obtain your API keys from the admin console.
Note: The API keys are different for your test site and your live site.
Note
Select the programming language of your choice from the Library dropdown at the top of the page.
This section shows you how to authenticate API calls using the Chargebee Billing client library.
For Node.js, use the Chargebee to configure your site and your API key. It is a global configuration and can be setup as part of your server initialization
const chargebee = new Chargebee({ site: "{site}", apiKey: "{site_api_key}", });
If you operate multiple Chargebee sites and need to target a specific site for an API call, simply specify the site name and corresponding API key in the API request. Here's an example of how to do this while calling the Create a customer API using the Chargebee Billing client library:
import Chargebee from "chargebee";
// Creating multiple instances of Chargebee for different sites.
const chargebeeSiteUS = new Chargebee({
apiKey: "{api-key}",
site: "{my-site-us}"
});
const chargebeeSiteEU = new Chargebee({
apiKey: "{api-key}",
site: "{my-site-eu}"
});
async function createCustomer() {
try {
const result = await chargebeeSiteUS.customer.create({
first_name: "Stuart",
last_name: "Little"
});
console.log(result);
const customer = result.customer;
} catch (err) {
console.log(err);
}
}
async function createCustomerEU() {
try {
const result = await chargebeeSiteEU.customer.create({
first_name: "Stuart",
last_name: "Little"
});
console.log(result);
const customer = result.customer;
} catch (err) {
console.log(err);
}
}
createCustomer();
createCustomerEU();
API keys are unique strings used for both authenticating and identifying an application communicating with Chargebee. This section describes the best practices that developers can follow to secure Chargebee API keys.
GET
requests do not generate any events, you can check API key usage for POST
requests by fetching all events with source
set to api
. Among the events returned, filter the API key name found in the event.user
attribute.
<service name>-<key creation timestamp>
(for example: core_app-09-12-2020
).