Bitrix24 REST API Automation Library
A comprehensive Python library that provides convenient high-level functions for interacting with the Bitrix24 REST API. Simplifies common CRM operations like managing leads, deals, contacts, users, and more.
pip install .Create a .env file in your project root with your Bitrix24 credentials:
BITRIX_ID=your_bitrix_id
CRM_USERTOKEN=/your_user_id/your_webhook_token
USER_USERTOKEN=/your_user_id/your_webhook_token
IMOPENLINES_USERTOKEN=/your_user_id/your_webhook_token
VOXIMPLANT_USERTOKEN=/your_user_id/your_webhook_token
TASKS_USERTOKEN=/your_user_id/your_webhook_token
DEPARTMENT_USERTOKEN=/your_user_id/your_webhook_token
IM_USERTOKEN=/your_user_id/your_webhook_tokenfrom dotenv import load_dotenv
load_dotenv()
import au_b24
# Initialize with rate limiting (optional)
au_b24.init_requests_pause(0.5) # 500ms pause between requests
# Get a lead
lead = au_b24.get_lead(123)
# Get leads with filters
leads = au_b24.get_leads(
filters={"STATUS_ID": "NEW"},
select=["ID", "TITLE", "NAME", "PHONE"],
order="ASC"
)
# Update a lead
au_b24.update_lead(123, {"TITLE": "Updated Title"})get_lead(lead_id)- Get single leadget_leads(filters, select, order, limit)- Get multiple leadsupdate_lead(lead_id, fields)- Update leaddelete_lead(lead_id)- Delete leadparse_leads(function)- Parse all leads with custom functionget_phone_by_lead(lead_id)- Extract phone number
get_deal(deal_id)- Get single dealget_deals(filters, select, order, limit)- Get multiple dealsupdate_deal(deal_id, fields)- Update dealdelete_deal(deal_id)- Delete dealparse_deals(function)- Parse all deals with custom function
get_contact(contact_id)- Get single contactget_contacts(filters, select, order, limit)- Get multiple contactsupdate_contact(contact_id, fields)- Update contactdelete_contact(contact_id)- Delete contactparse_contacts(function)- Parse all contacts with custom functionget_phone_by_contact(contact_id)- Extract phone number
get_product(product_id)- Get single productget_products(filters, select, order, limit)- Get multiple productscreate_product(name, fields)- Create new productupdate_product(product_id, fields)- Update productdelete_product(product_id)- Delete product
get_smart(entity_id, smart_id)- Get single smart process itemget_smarts(entity_id, filters, select, order, limit)- Get multiple itemsupdate_smart(entity_id, smart_id, fields)- Update smart process itemparse_smarts(function)- Parse smart process items with custom function
get_user(user_id)- Get user informationget_users(filters)- Get multiple usersupdate_user(user_id, user_data)- Update userget_user_name(user_id)- Get formatted user name
get_statuses()- Get lead statusesget_sources()- Get lead sourcesget_stages(category_id)- Get deal stagesget_deal_categories()- Get deal categoriesget_stage_history(entity_type, entity_id)- Get status/stage change history
get_openlines(entity_id, entity_type)- Get open lines for entityget_last_openline_id(entity_id, entity_type)- Get last open line IDtransfer_openline(ol_id, user_id)- Transfer open line to userintercept_openline(ol_id)- Intercept open lineget_openline_messages(openline_id, session_id)- Get messagesnotify_user(user_id, message)- Send notification to user
add_comment(entity_id, entity_type, text)- Add comment to entityget_comments(entity_id, entity_type, select)- Get entity comments
get_calls(filters, order, limit)- Get call records
get_tasks(filters, select, order)- Get tasksadd_task(title, created_by, responsible_id, extra_fields)- Create taskdelete_task(task_id)- Delete taskparse_tasks(function)- Parse all tasks with custom function
get_department(dep_id)- Get department infoget_all_departaments()- Get all departments
get_enumerated_field_values(entity_type, field_id)- Get enum field optionsextract_enumerated_field_value(entity_type, field_id, value)- Extract enum valueextract_enumerated_smart_field_value(entity_id, field_id, value)- Extract smart enum value
create_crm_link(entity_type, entity_id)- Generate CRM entity linkto_unix_time(datetime)- Convert ISO datetime to Unix timestamp
def process_lead(lead):
print(f"Processing lead {lead['ID']}: {lead['TITLE']}")
if lead['STATUS_ID'] == 'CONVERTED':
au_b24.update_lead(lead['ID'], {'STATUS_ID': 'PROCESSED'})
# Use the decorator to parse all leads
@au_b24.parse_leads
def my_lead_processor(lead):
process_lead(lead)
# Execute parsing
my_lead_processor(
filters={'STATUS_ID': 'NEW'},
select=['ID', 'TITLE', 'STATUS_ID']
)# Get smart process items
smarts = au_b24.get_smarts(
entity_id=1234, # Smart process type ID
filters={'stageId': 'NEW'},
select=['id', 'title', 'stageId']
)
# Update smart process item
au_b24.update_smart(1234, 5678, {'title': 'Updated Title'})# Set pause between requests to avoid rate limits
au_b24.init_requests_pause(0.5) # 500ms pausefrom au_b24 import StopParsing
@au_b24.parse_leads
def selective_processor(lead):
if lead['ID'] > 1000:
raise StopParsing() # Stop processing
# Process lead...
selective_processor(filters={}, select=['ID'])The library includes comprehensive error handling and logging. Set up logging to see detailed information:
import logging
logging.basicConfig(level=logging.INFO)- All
get_entitiesfunctions provide only ID-based ordering - Rate limiting is recommended to avoid API limits
- ID filtering in entity functions uses special operators (
>ID,<ID) - Smart processes support full ID filtering including comparison operators
- Some functions return
Noneon error, others returnFalseor empty lists
- Python 3.8+
- requests
- cachetools
- python-dotenv
MIT License