You are viewing the documentation for the older version of our API (V1). Click here for information on upgrading to the latest version (V2).
You are viewing the documentation for the older version of our API (V1). Click here for information on upgrading to the latest version (V2).

Getting started

Chargebee provides HTTP based API which follows the essence of REST*. The HTTP protocol's rules are followed thereby enabling simple HTTP client tools like "curl" to be used.

The following client libraries provide a "easy to use" wrapper around the raw HTTP based API.

Please do mail us at support if you need any other language bindings.

Sample Snippets

The top language bar allows you to see samples in your preferred language.

Want us to generate ready-to-test snippets?

to Chargebee and open the API docs from there and you'll find ready-to-test sample codes based on your Chargebee test site's api key and data.
Don't have an account with Chargebee yet? .

Sample Apps

Checkout our collection of sample applications with tutorials on integrating with Chargebee.

Documentation

Refer to our documentation for a detailed definition & description of all the components in Chargebee.

r a detailed definition & description of all the components in Chargebee.

Chargebee follows the REST model of exposing resources as urls. For example, subscriptions are exposed as

https://{site}.chargebee.com/api/v1/subscriptions

Request

The HTTP method (like GET,POST) determines the operation type on the resource. Query parameters allow you to provide additional options to the GET requests. POST parameters provide the data to write operations like creation, modification of resource(s).

By default curl uses GET method. Use -X option to specify a specific HTTP method to use. For passing parameters, use -d option. ( Note: cURL automatically uses to POST method if any parameter is sent via -d option ).

Response

The response is in JSON format. Currently Chargebee does not support any other response format.

Note: Sometimes, while working with Chargebee APIs, you may see undocumented attributes returned in the response. Such attributes should be ignored.

Sample Request
# creates a subscription with customer information and billing details.
curl  https://{site}.chargebee.com/api/v1/subscriptions \
     -u {site_api_key}:\
     -d plan_id="no_trial" \
     -d customer[first_name]="John" \
     -d customer[last_name]="Doe" \
     -d customer[email]="john@user.com" \
     -d billing_address[first_name]="John" \
     -d billing_address[last_name]="Doe" \
     -d billing_address[line1]="PO Box 9999" \
     -d billing_address[city]="Walnut" \
     -d billing_address[state]="California" \
     -d billing_address[zip]="91789" \
     -d billing_address[country]="US" \
     -d customer[auto_collection]="off"
copy
# creates a subscription with customer information and billing details.
curl  https://{site}.chargebee.com/api/v1/subscriptions \
     -u {site_api_key}:\
     -d plan_id="no_trial" \
     -d customer[first_name]="John" \
     -d customer[last_name]="Doe" \
     -d customer[email]="john@user.com" \
     -d billing_address[first_name]="John" \
     -d billing_address[last_name]="Doe" \
     -d billing_address[line1]="PO Box 9999" \
     -d billing_address[city]="Walnut" \
     -d billing_address[state]="California" \
     -d billing_address[zip]="91789" \
     -d billing_address[country]="US" \
     -d customer[auto_collection]="off"

Sample Response [ JSON ]

Show more...
{ "customer": { "account_credits": 0, "allow_direct_debit": false, "auto_collection": "off", "billing_address": { "city": "Walnut", "country": "US", "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "object": "billing_address", "state": "California", "state_code": "CA", "zip": "91789" }, "card_status": "no_card", "created_at": 1517506669, "email": "john@user.com", "excess_payments": 0, "first_name": "John", "id": "__test__5SK0bLNFRFuBv6r6j", "last_name": "Doe", "object": "customer", "refundable_credits": 0, "taxability": "taxable" }, "invoice": { "amount": 895, "amount_adjusted": 0, "amount_due": 895, "amount_paid": 0, "billing_address": { "city": "Walnut", "country": "US", "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "object": "billing_address", "state": "California", "state_code": "CA", "zip": "91789" }, "credits_applied": 0, "currency_code": "USD", "customer_id": "__test__5SK0bLNFRFuBv6r6j", "end_date": 1517506669, "first_invoice": true, "id": "__demo_inv__7", "line_items": [ { "amount": 895, "date_from": 1517506669, "date_to": 1519925869, "description": "No Trial", "entity_id": "no_trial", "entity_type": "plan", "is_taxed": false, "object": "line_item", "quantity": 1, "tax": 0, "type": "charge", "unit_amount": 895 }, {..} ], "linked_orders": [], "linked_transactions": [], "object": "invoice", "price_type": "tax_exclusive", "recurring": true, "start_date": 1517506669, "status": "payment_due", "sub_total": 895, "subscription_id": "__test__5SK0bLNFRFuBv6r6j", "tax": 0 }, "subscription": { "activated_at": 1517506669, "created_at": 1517506669, "current_term_end": 1519925869, "current_term_start": 1517506669, "due_invoices_count": 1, "due_since": 1517506669, "has_scheduled_changes": false, "id": "__test__5SK0bLNFRFuBv6r6j", "object": "subscription", "plan_id": "no_trial", "plan_quantity": 1, "started_at": 1517506669, "status": "active", "total_dues": 895 } }

You can use cURL to test Chargebee API from a CLI. When you pass input parameters to the API using -d or --data-urlencode options, the HTTP POST method is used:

curl https://{site}.chargebee.com/api/v1/subscriptions/{subscription_id}/change_term_end
    -u {site_api_key}:\
    -d term_ends_at=1601490600

When no input parameters are provided, cURL uses the GET method by default:
curl https://{site}.chargebee.com/api/v1/subscriptions/{subscription_id} \
    -u {site_api_key}:

To make a POST request without providing any input parameters, use the -X POST option:
curl -X POST https://{site}.chargebee.com/api/v1/exports/subscriptions \     -u {site_api_key}:

Further, to make GET requests with parameters, you must use the -G option:
curl -X POST https://{site}.chargebee.com/api/v1/v2/orders \
    -G  \
    -u {site_api_key}:\
    --data-urlencode limit=3 \
    --data-urlencode status[is]="queued"

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.

Additional developer resources

Check out our collection of sample applications and related tutorials for integrating with Chargebee.