Implementation:Mage ai Mage ai Chargebee Client
| Knowledge Sources | |
|---|---|
| Domains | Data_Integration, Chargebee, API |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
Concrete HTTP client for making authenticated requests to the Chargebee API, provided by the Mage Chargebee source connector.
Description
The ChargebeeClient class encapsulates all HTTP communication with the Chargebee REST API. It authenticates using HTTP Basic Auth with the api_key from the configuration (password is empty). The client enforces rate limiting via the Singer @utils.ratelimit(100, 60) decorator, allowing a maximum of 100 requests per 60 seconds. It includes a comprehensive error handling hierarchy with custom exception classes mapped to HTTP status codes (400, 401, 403, 404, 405, 409, 429, 500, 503). The client supports configurable request timeouts (defaulting to 300 seconds) and result pagination via api_result_limit. Key methods include make_request for executing HTTP calls and get_params/get_headers for request preparation.
Usage
Used internally by Chargebee stream classes to fetch data from the Chargebee API. Requires api_key and site in the config dictionary. Optionally accepts user_agent, include_deleted, and request_timeout configuration parameters.
Code Reference
Source Location
- Repository: mage-ai
- File:
mage_integrations/mage_integrations/sources/chargebee/client.py - Lines: 1-195
Signature
class ChargebeeClient():
def __init__(self, config, api_result_limit=100, include_deleted=True):
Import
from mage_integrations.sources.chargebee.client import ChargebeeClient
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config | dict | Yes | Configuration dictionary containing api_key, site, optional user_agent, include_deleted, and request_timeout
|
| api_result_limit | int | No | Maximum number of results per API request (default: 100) |
| include_deleted | bool | No | Whether to include deleted records (default: True) |
Outputs
| Name | Type | Description |
|---|---|---|
| response | dict | Parsed JSON response from the Chargebee API |
Key Methods
| Method | Description |
|---|---|
make_request(url, method, params=None, body=None) |
Executes an HTTP request with rate limiting, authentication, and error handling. Returns parsed JSON. |
get_headers() |
Returns request headers dictionary, including optional User-Agent. |
get_params(params) |
Merges provided params with limit and include_deleted defaults.
|
Error Handling
Defines a hierarchy of custom exceptions mapped to HTTP status codes:
| Status Code | Exception Class |
|---|---|
| 400 | ChargebeeBadRequestError
|
| 401 | ChargebeeAuthenticationError
|
| 403 | ChargebeeForbiddenError
|
| 404 | ChargebeeNotFoundError
|
| 405 | ChargebeeMethodNotAllowedError
|
| 409 | ChargebeeNotProcessedError
|
| 429 | ChargebeeRateLimitError
|
| 500 | ChargebeeInternalServiceError
|
| 503 | ChargebeeServiceUnavailableError
|
Usage Examples
from mage_integrations.sources.chargebee.client import ChargebeeClient
config = {
'api_key': 'your_chargebee_api_key',
'site': 'your-site',
'user_agent': 'MageIntegration/1.0',
'include_deleted': True,
'request_timeout': 300,
}
client = ChargebeeClient(config, api_result_limit=100)
response = client.make_request(
url='https://your-site.chargebee.com/api/v2/subscriptions',
method='GET',
params={'status[is]': 'active'},
)