Python SDK for IM CSM API
This SDK provides a simple and efficient way to interact with the IM CSM API from Python applications. It allows you to manage contacts, send and list messages, create and manage shortlinks, and check API status with easy-to-use functions and Pydantic models.
The API has rate limits to ensure fair usage:
- Shortlinks: Maximum of 10 shortlinks created per minute per account (default)
- When you exceed the limit, you'll receive a 403 error with code
42900 - For inquiries or requests to increase the limit: Please contact Technical Support directly through their support channels
Example error response:
{
"code": 42900,
"error": "Ha excedido el límite de solicitudes. Intente nuevamente más tarde"
}- Python 3.8+
- Pydantic v2
- FastAPI (for advanced usage)
- Other dependencies are listed in
pyproject.toml
# Create and activate a virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies using requirements.txt
pip install -r requirements.txt# Install uv if you haven't already
pip install uv
# Create and activate a virtual environment
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
uv syncIf your SDK requires configuration (e.g., API keys, endpoints), set them as environment variables or in a config file. See im_csm_sdk_python/configs/config.py for details.
You can test the SDK using the provided example script:
python example/main.pyThis script demonstrates how to list messages, send a message, interact with contacts, and manage shortlinks. Check the code in example/main.py for more details and usage patterns.
You can run individual shortlink scenarios (mirroring the Java/JS runners) without editing the script:
python example/main.py shortlinks # Flujo completo (create + list + id + update)
python example/main.py shortlinks run # Idéntico al flujo completo
python example/main.py shortlinks create https://midominio.com/landing "Demo Python" ACTIVE miAlias
python example/main.py shortlinks list 20 -6 # Límite y offset
python example/main.py shortlinks date 2025-01-01 2025-12-31 20 -6
python example/main.py shortlinks id 123ABC # Usa un url_id real
python example/main.py shortlinks update 123ABC INACTIVE
python example/main.py shortlinks status # Muestra estados permitidosNotas:
- El alias es opcional; si lo omites se genera uno aleatorio de 8 caracteres.
- El comando
updatesolo aceptaINACTIVE, igual que la API; la reactivación no está soportada. - Para comandos
listydate,offsetrepresenta el desfase horario (por ejemplo-6para Centroamérica).
python -m pip install -r requirements.txt# Run all examples (including shortlinks)
python example/main.pyfrom im_csm_sdk_python import list_shortlinks, create_shortlink
from im_csm_sdk_python.schemas.shortlinks import CreateShortlinkData, ListShortlinksParams
# List shortlinks
shortlinks = list_shortlinks(ListShortlinksParams(limit=10))
print(f"Found {len(shortlinks)} shortlinks")
# Create shortlink
created = create_shortlink(
CreateShortlinkData(
long_url="https://www.example.com/test",
name="Test Shortlink",
alias="campaign_alias",
status="ACTIVE"
)
)
print(f"Created: {created.short_url}")
> **Alias rules:** 1–30 printable characters, no spaces. Provide a custom alias only when you need a predictable slug; otherwise omit it and the platform will auto-generate one. Re-using the same alias on the same domain returns `500 Bad Request` from the ShortURL API. Shortlinks can be deactivated but **not** reactivated. Names are trimmed and limited to 50 characters.- Status
- Get API status:
im_csm_sdk_python.get_status()
- Get API status:
- Contacts
- List contacts:
im_csm_sdk_python.list_contacts(params) - Get a contact:
im_csm_sdk_python.get_contact(msisdn)
- List contacts:
- Messages
- List messages:
im_csm_sdk_python.list_messages(params) - Send message to contact:
im_csm_sdk_python.send_to_contact(data) - Send message to tags:
im_csm_sdk_python.send_to_tags(data)
- List messages:
- Shortlinks
- List shortlinks:
im_csm_sdk_python.list_shortlinks(params) - Get shortlink by ID:
im_csm_sdk_python.get_shortlink_by_id(shortlink_id) - Create shortlink:
im_csm_sdk_python.create_shortlink(data)(alias optional, 1–30 chars, no spaces) - Update shortlink status:
im_csm_sdk_python.update_shortlink_status(shortlink_id, status)(onlyINACTIVEis accepted)
- List shortlinks:
{
"success": true,
"message": "Shortlink created successfully",
"account_id": 12345,
"url_id": "123ABC",
"short_url": "https://shorturl-pais.com/123ABC",
"alias": "campaign_alias",
"long_url": "https://www.example.com/very-long-url-with-parameters"
}{
"success": true,
"message": "Shortlinks retrieved successfully",
"data": [
{
"_id": "123ABC",
"account_uid": "abcde12345678kklm",
"name": "Enlace corto de prueba",
"status": "INACTIVE",
"base_url": "https://shorturl-pais.com/",
"short_url": "https://shorturl-pais.com/123ABC",
"alias": "campaign_alias",
"long_url": "https://www.example.com/long-url-here",
"visits": 0,
"unique_visits": 0,
"preview_visits": 0,
"created_by": "SHORTLINK_API",
"reference_type": "SHORT_LINK",
"expiration": false,
"expiration_date": null,
"created_on": 1735689600000
}
],
"account_id": 12345
}{
"success": true,
"message": "Shortlink found",
"account_id": 12345,
"url_id": "123ABC",
"short_url": "https://shorturl-pais.com/123ABC",
"alias": "campaign_alias",
"long_url": "https://www.example.com/long-url-with-parameters",
"name": "Example Shortlink",
"status": "ACTIVE",
"visits": 0,
"unique_visits": 0,
"preview_visits": 0,
"created_by": "SHORTLINK_API",
"created_on": 1735689600000
}{
"success": false,
"message": "Shortlink not found"
}Feel free to open issues or submit pull requests to improve the SDK. Please ensure your code follows the project's style guidelines and includes appropriate tests.