Implementation:Mage ai Mage ai Commercetools Client
| Knowledge Sources | |
|---|---|
| Domains | Data_Integration, Commercetools, API |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
Concrete HTTP client for making authenticated requests to the Commercetools API, provided by the Mage Commercetools source connector.
Description
The Client class extends BaseClient from mage_integrations.sources.http.client to implement OAuth2 client credentials authentication against the Commercetools platform. During initialization, it obtains an access token by posting client credentials (client_id and client_secret) to the Commercetools OAuth endpoint. The base URL is dynamically constructed from region, host, and project_key configuration values. The client sets Authorization: Bearer and Content-Type: application/json headers on all requests. It provides a request method that delegates to the inherited make_request method.
Usage
Used internally by Commercetools stream classes to fetch data from the Commercetools API. Requires region, host, project_key, client_id, and client_secret in the config dictionary.
Code Reference
Source Location
- Repository: mage-ai
- File:
mage_integrations/mage_integrations/sources/commercetools/client.py - Lines: 1-55
Signature
class Client(BaseClient):
def __init__(self, config: Dict, logger):
Import
from mage_integrations.sources.commercetools.client import Client
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config | Dict | Yes | Configuration with region, host, project_key, client_id, client_secret
|
| logger | Logger | Yes | Logger instance for diagnostic output |
Outputs
| Name | Type | Description |
|---|---|---|
| response | dict | Parsed JSON API response from Commercetools |
Key Methods
| Method | Description |
|---|---|
get_access_token() |
Posts client credentials to the Commercetools OAuth endpoint and returns the access token string. |
get_headers() |
Returns headers dict with Bearer token Authorization and JSON Content-Type. |
request(method, path, url, params, body) |
Constructs the full URL from base_url + path (if url not provided) and delegates to make_request.
|
base_url (property) |
Dynamically constructs the API base URL from region, host, and project_key config values. |
Usage Examples
from mage_integrations.sources.commercetools.client import Client
config = {
'region': 'us-central1',
'host': 'gcp',
'project_key': 'my-project',
'client_id': 'your_client_id',
'client_secret': 'your_client_secret',
}
client = Client(config, logger)
response = client.request(method='get', path='/products')