Chargebee provides an HTTP-based API that follows the principles of REST. The HTTP rules followed allow simple HTTP clients like cURL to be used as well. The URLs are resource-oriented, the request format is form-encoded, and the responses are in JSON.
Depending on the type of operation, the endpoints use one of two HTTP methods:
GET: Used for all read-only operations such as retrieving a resource or listing a group of resources.
POST: Used for all write operations. Such operations modify the state of a resource.
A history of changes to the API is provided in the API Changelog.
Note
Sometimes, while working with Chargebee APIs, you may see undocumented attributes returned in the response. Such attributes should be ignored.
Early Access Program
Some features in the API are part of the Early Access Program and are labeled "EAP," "Beta," or "Early Access." Please review the terms and conditions that apply to these features before using them.
Resources
Chargebee follows the REST model of exposing resources as urls. For example, subscriptions are exposed as
https://{site}.chargebee.com/api/v2/subscriptions
The Java client library provide a corresponding class representation of the resource. For example, subscriptions are represented by
com.chargebee.models.Subscription
Request
The client library exposes all operations specific to that resource as static methods in the corresponding resource class and they return a operation specific Request object. The "Request" objects expose a
fluent API using which you could set the
input parameters for the operation. After filling in the request parameters, invoke the request method to send the request. There is an additional overloaded request method that takes in environment configuration that is applied only for that request.
Response
The response is in JSON format.
Currently Chargebee does not support any other response format.
The com.chargebee.Result class wraps the response sent by the server. It has methods
that allow you to fetch the specific resource from the result.
The com.chargebee.ListResult class is used to wrap list responses.
Note: Sometimes, while working with Chargebee APIs, you may see undocumented attributes returned in the response. Such attributes should be ignored.
Sample Codes
import java.io.IOException;
import com.chargebee.*;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
public class Sample{
public static void main(String args[]) throws IOException{
Environment.configure("{site}","{site_api_key}");
Result result = Subscription.createWithItems("__test__8asz8Ru9WhHOJO")
.subscriptionItemItemPriceId(0,"basic-USD")
.subscriptionItemBillingCycles(0,2)
.subscriptionItemQuantity(0,1)
.subscriptionItemItemPriceId(1,"day-pass-USD")
.subscriptionItemUnitPrice(1,100)
.request();
Subscription subscription = result.subscription();
Customer customer = result.customer();
Card card = result.card();
Invoice invoice = result.invoice();
List unbilledCharges = result.unbilledCharges();
System.out.println(result);
}
}
To view this API reference tailored to the programming language of your choice, select the language in the “Library” dropdown above. Reach out to us at Chargebee Support if you’d like to request any other language bindings.
Java client library
Note
Select the programming language of your choice from the “Library” dropdown at the top of the page.
The client libraries for this API are open source and are available on GitHub under the MIT license.
INSTALL THE LIBRARY
You can install the library via Maven or by adding a JAR file to your project.
INSTALL USING MAVEN
You can install the library by adding the following dependency to pom.xml.
You can find the JAR files for the library in the dist directory. To obtain the JAR files for a specific library version, check the dist directory within the source tree of the appropriate tag.
IMPORT PACAKAGES
Once the library is installed, import the following packages within your source code.
As part of our commitment to enhance the developer experience, we're thrilled to introduce the Chargebee OpenAPI specification. It's the first step in a series of planned improvements.
The Chargebee OpenAPI specification is a version of our API spec that is fully compliant with the OpenAPI Specification v3.0.1. Stay tuned for more updates!
Code samples
The sample code snippets provided for the endpoints in this documentation are ready-to-test. Once you log in and select a test site using the dropdown that appears at the top, the code samples in this documentation automatically include your API key and site data.
API testing
Chargebee provides the Time Machine feature to help you test your integration. Once you've set up your billing configuration on the test site, you can simulate events on a hypothetical time frame to ensure everything works as expected. Ensure that you rigorously test your configuration before going live.