chargebee chatChat with us

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@chargebee.com if you need any other language bindings.

Sample Snippets

Want us to generate ready-to-test snippets to use with your ChargeBee sandbox site?
to ChargeBee and open the API docs from there and you'll find ready to use sample codes here. Don't have an account with Chargebee yet? .

Sample Apps

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

Need more help with the terminologies?

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

Installing Python Library

The library can be installed as
pip install --upgrade chargebee
or
easy_install --upgrade chargebee
To install from source:
python setup.py install
Then import as:
import chargebee

Source Code

The source code for the client library is available as a public repository at github. The code is provided with MIT license. So in case you need any modifications please feel free to do so. If you think it would be useful for other users please do let us know.

Chargebee uses HTTP BASIC Auth for authenticating the api calls. The user name is your "api key" and the password is empty. The api key could be got from 'Your Api Keys' page under integration tab in the web client console.

Note: The api keys are different for your sandbox site and your production site.

Authentication in python

Use the Environment class to configure your site and your api key.

chargebee.configure("{site_api_key}","{site}")

Resources

ChargeBee follows the REST model of exposing resources as urls.
The following resources are exposed via the api.

Resource model classes

The following readonly python classes model the corresponding resources

  • chargebee.Subscription
  • chargebee.Customer
  • chargebee.Card
  • chargebee.Invoice
  • chargebee.Transaction
  • chargebee.HostedPage
  • chargebee.Estimate
  • chargebee.Plan
  • chargebee.Addon
  • chargebee.Coupon
  • chargebee.CouponCode
  • chargebee.Address
  • chargebee.Event
  • chargebee.Comment
  • chargebee.Download

Operations

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).

Invoking operations in python

All operations specific to that resource are exposed as class methods in the corresponding resource class. The methods accepts the input params as hash and returns a result object.

Response

The response is in JSON format. Currently we are not supporting any other format.

Result & ListResult classes

The Result class wraps the response sent by the server.It has methods that allow you to fetch the specific resource from the result. The ListResult class is used to wrap list responses.

subscription = result.subscription 

HTTP status code is used to indicate success or failure of an API call. The detailed error code and description is present in the JSON content in response body.

The standard response codes are used.

  • 2XX The response code in this range implies the API call has succeeded.
  • 3XX This range is not used currently.
  • 4XX response codes indicate failure due to wrong input (i.e, client) side.
    Notable among them are:
    • 400 - Bad request - Mostly due to missing or malformed parameters. The specific error type is present in the error code attribute in the content.
    • 401 - Unauthorized - The Authorization header required for basic authentication is either missing or contains invalid site + API key combo.
    • 403 - Forbidden - The API key is valid but the operation is not allowed due to security constraints.
    • 404 - Not Found - The requested resource is not found.
  • 5XX response codes indicate API request was valid but failed due to bugs on the ChargeBee server side.

For error responses from the server APIError is thrown.

Sample error response in JSON:

{ http_code:"400", error_code:"param_not_present", message:"plan_id is not present", param:"plan_id", }