wrapper for amocrm rest api
Install
Install using pip
...
pip install amocrm-api-wrapper
Usage
=======
from amocrm_api import AmoLegacyClient # for login password auth
from amocrm_api import AmoOAuthClient # for oauth
from datetime import datetime
client = AmocrmLegacyClient('<login>', '<password>', '<crm_url>')
client = AmocrmOAuthClient('<access_token>', '<refresh_token>', '<crm_url>', '<client_id>', '<client_secret>', '<redirect_uri>')
dt = datetime.datetime.today().strftime("%a, %d %b %Y %H-%m-%d")
date_time = f"{dt} UTC"
# for Legacy client
headers = {
"IF-MODIFIED-SINCE": f"{date_time}",
"Content-Type": "application/json",
}
client.update_session_params(headers)
get account info
name |
type |
default value |
with_amojo_id |
bool |
False |
with_amojo_rights |
bool |
False |
with_users_groups |
bool |
False |
with_task_types |
bool |
False |
with_version |
bool |
False |
with_ventity_names |
bool |
False |
with_datetime_settings |
bool |
False |
account_info = client.get_account_info()
create leads
name |
type |
default value |
objects |
list |
- |
objects = [
{
"name": "Сделка для примера 1",
"created_by": 0,
"price": 20000,
"custom_fields_values": [
{
"field_id": 294471,
"values": [
{
"value": "Наш первый клиент"
}
]
}
]
},
{
"name": "Сделка для примера 2",
"price": 10000,
"_embedded": {
"tags": [
{
"id": 2719
}
]
}
}
]
result = client.create_leads(objects)
update leads
name |
type |
default value |
objects |
list |
- |
objects = [
{
"id": 54886,
"pipeline_id": 47521,
"status_id": 143,
"date_close": 1589297221,
"loss_reason_id": 7323,
"updated_by": 0
},
{
"id": 54884,
"price": 50000,
"pipeline_id": 47521,
"status_id": 525743,
"_embedded": {
"tags": None
}
}
]
result = client.update_leads(objects)
get lead
name |
type |
default value |
lead_id |
int |
- |
lead = client.get_lead(123)
get leads
name |
type |
default value |
limit |
int |
250 |
page |
int |
1 |
with_params |
Optional[list] |
None |
filters |
Optional[dict] |
None |
order |
Optional[dict] |
None |
leads = client.get_leads(limit=10, page=3, filters={'[updated_at][from]': '<timestamp>'})
get unsorted leads
name |
type |
default value |
limit |
int |
250 |
page |
int |
1 |
filter_by_uids |
Union[str, list, None] |
None |
filter_by_pipeline_id |
Union[str, list, None] |
None |
filter_by_category |
Union[str, list, None] |
None |
order_by |
Optional[dict] |
None |
unsorted_leads = client.get_unsorted_leads(limit=10, page=3, filter_by_pipeline_id=[1, 2310, 8751035])
get unsorted lead by uid
name |
type |
default value |
uid |
str |
- |
unsorted_lead = client.get_unsorted_by_uid('ufsigkgdjlk13igmd')
create unsorted lead by sip
name |
type |
default value |
source_uid |
str |
- |
source_name |
str |
- |
metadata |
dict |
- |
conctact |
dict |
- |
lead |
dict |
- |
comapany |
dict |
- |
pipeline_id |
Optional[int] |
None |
created_at |
Optional[int] |
None |
request_id |
Optional[int] |
None |
unsorted_lead = {
"request_id": "123",
"source_name": "ОАО Коспромсервис",
"source_uid": "a1fee7c0fc436088e64ba2e8822ba2b3",
"pipeline_id": 2194576,
"created_at": 1510261200,
"leads": {
"name": "Тех обслуживание",
"price": 5000,
"custom_fields_values": [
{
"field_id": 284785,
"values": [
{
"value": "Кастомное поле"
}
]
}
],
"_embedded": {
"tags": [
{
"id": 263809
}
]
}
}
],
"contacts":
{
"name": "Контакт для примера"
}
"companies":
{
"name": "ОАО Коспромсервис"
}
},
"metadata": {
"is_call_event_needed": True,
"uniq": "a1fe231cc88e64ba2e8822ba2b3ewrw",
"duration": 54,
"service_code": "CkAvbEwPam6sad",
"link": "https://example.com",
"phone": 79998888888,
"called_at": 1510261200,
"from": "onlinePBX"
}
}
result = client.create_unsorted_by_sip(**unsorted_lead)
create unsorted lead by form
name |
type |
default value |
source_uid |
str |
- |
source_name |
str |
- |
metadata |
dict |
- |
conctact |
dict |
- |
lead |
dict |
- |
comapany |
dict |
- |
pipeline_id |
Optional[int] |
None |
created_at |
Optional[int] |
None |
request_id |
Optional[int] |
None |
unsorted_lead = {
"request_id": "123",
"source_name": "ОАО Коспромсервис",
"source_uid": "a1fee7c0fc436088e64ba2e8822ba2b3",
"pipeline_id": 2194576,
"created_at": 1590830520,
"leads": {
"name": "Тех обслуживание",
"visitor_uid": "5692210d-58d0-468c-acb2-dce7f93eef87",
"price": 5000,
"custom_fields_values": [
{
"field_id": 284785,
"values": [
{
"value": "Дополнительное поле"
}
]
}
],
"_embedded": {
"tags": [
{
"name": "Тег для примера"
}
]
}
},
"contacts":
{
"name": 234,
"first_name": "123213",
"last_name": 234,
"custom_fields_values": [
{
"field_code": "PHONE",
"values": [
{
"value": "+7912321323"
}
]
}
]
},
"companies": {
"name": "ОАО Коспромсервис"
},
"metadata": {
"ip": "123.222.2.22",
"form_id": "a1fee7c0fc436088e64ba2e8822ba2b3ewrw",
"form_sent_at": 1590830520,
"form_name": "Форма заявки для полёта в космос",
"form_page": "https://example.com",
"referer": "https://www.google.com/search?&q=elon+musk"
}
}
result = client.create_unsorted_by_form(**unsorted_lead)
accept unsorted lead
name |
type |
default value |
uid |
str |
- |
user_id |
int |
- |
status_id |
int |
- |
result = client.accept_unsorted('jkjsoijg2321kgkdu2', 2310, 4444)
decline unsorted lead
name |
type |
default value |
uid |
str |
- |
user_id |
int |
- |
result = client.decline_unsorted('jkjsoijg2321kgkdu2', 2310,)
link unsorted lead ot another lead
name |
type |
default value |
uid |
str |
- |
user_id |
int |
- |
link |
dict |
- |
result = client.link_unsorted('jkjsoijg2321kgkdu2', 2310, link={
"entity_id": 93144801,
"entity_type": "leads"
})
get summary unsorted leads
name |
type |
default value |
uid |
Union[str, list, None] |
None |
created_at__from |
Optional[str] |
None |
created_at__to |
Optional[str] |
None |
pipeline_id |
Union[str, list, None] |
None |
summary_unsorted = client.get_summary_unsorted()
get pipelines
pipelines = client.get_pipelines()
craete pipeline
name |
type |
default value |
name |
str |
- |
sort |
int |
- |
is_main |
bool |
- |
statuses |
list |
- |
is_unsorted_on |
bool |
False |
request_id |
Optional[str] |
None |
pipeline = {
"name": "Воронка доп продаж",
"is_main": False,
"is_unsorted_on": True,
"sort": 20,
"request_id": "123",
"statuses": [
{
"id": 142,
"name": "Мое название для успешных сделок"
},
{
"name": "Первичный контакт",
"sort": 10,
"color": "#fffeb2"
}
]
}
result = client.create_pipeline(**pipeline)
edit pipeline
name |
type |
default value |
pipeline_id |
int |
- |
name |
str |
- |
sort |
int |
- |
is_main |
bool |
- |
is_unsorted_on |
bool |
False |
pipeline = {
"pipeline_id": 2310,
"name": "Новое название для воронки",
"is_main": False,
"is_unsorted_on": False,
"sort": 100
}
result = client.edit_pipeline(**pipeline)
delete pipeline
name |
type |
default value |
pipeline_id |
int |
- |
result = client.delete_pipeline(2310)
get statuses by pipeline
name |
type |
default value |
pipeline_id |
int |
- |
pipeline_statuses = client.get_pipeline_statuses(2310)
get pipeline status
name |
type |
default value |
pipeline_id |
int |
- |
status_id |
int |
- |
pipeline_status = client.get_pipeline_status(2310, 123)
add statuses to pipeline
name |
type |
default value |
pipeline_id |
int |
- |
statuses |
list |
- |
statuses = [
{
"name": "Новый этап",
"sort": 100,
"color": "#fffeb2"
},
{
"name": "Новый этап 2",
"sort": 200,
"color": "#fffeb2"
}
]
result = client.add_statuses_to_pipeline(2310, statuses)
edit pipeline status
name |
type |
default value |
pipeline_id |
int |
- |
status_id |
int |
- |
name |
str |
- |
sort |
int |
- |
color |
str |
- |
result = client.edit_pipeline_status(2310, 123, 'Новый Этап', sort=500, color="#fffeb2")
delete status from pipeline
name |
type |
default value |
pipeline_id |
int |
- |
status_id |
int |
- |
result = client.delete_status_from_pipeline(2310, 123)
get contacts
name |
type |
default value |
limit |
int |
250 |
page |
int |
1 |
with_params |
Optional[list] |
None |
filters |
Optional[dict] |
None |
order |
Optional[dict] |
None |
contacts = client.get_contacts(limit=10, page=3, filters={'[updated_at][from]': '<timestamp>'})
get contact
name |
type |
default value |
contact_id |
int |
- |
contact = client.get_contact(123989)
create contacts
name |
type |
default value |
contacts |
list |
- |
conctacts = [
{
"first_name": "Петр",
"last_name": "Смирнов",
"custom_fields_values": [
{
"field_id": 271316,
"values": [
{
"value": "Директор"
}
]
}
]
},
{
"name": "Владимир Смирнов",
"created_by": 47272
}
]
result = client.create_contacts(contacts)
update contacts
name |
type |
default value |
contacts |
list |
- |
conctacts = [
{
"id": 3,
"first_name": "Иван",
"last_name": "Иванов",
"custom_fields_values": [
{
"field_id": 66192,
"field_name": "Телефон",
"values": [
{
"value": "79999999999",
"enum_code": "WORK"
}
]
}
]
}
]
result = client.update_contacts(contacts)
get companies
name |
type |
default value |
limit |
int |
250 |
page |
int |
1 |
with_params |
Optional[list] |
None |
filters |
Optional[dict] |
None |
order |
Optional[dict] |
None |
companies = client.get_companies(limit=10, page=3, filters={'[updated_at][from]': '<timestamp>'})
get company
name |
type |
default value |
company_id |
int |
- |
company = client.get_company(9988)
create companies
name |
type |
default value |
companies |
list |
- |
companies = [
{
"name": "АО Рога и Копыта",
"custom_fields_values": [
{
"field_code": "PHONE",
"values": [
{
"value": "+7912322222",
"enum_code": "WORK"
}
]
}
]
}
]
result = client.create_companies(companies)
update companies
name |
type |
default value |
companies |
list |
- |
companies = [
{
"id": 11090825,
"name": "Новое название компании",
"custom_fields_values": [
{
"field_code": "EMAIL",
"values": [
{
"value": "test@example.com",
"enum_code": "WORK"
}
]
}
]
}
]
result = client.update_companies(companies)
get catalogs
catalogs = client.get_catalogs(page=1, limit=5)
get catalog
catalog = client.get_catalog(12319)
create catalogs
name |
type |
default value |
catalogs |
list |
- |
catalogs = [
{
"name": "Тестовый список",
"can_add_elements": True,
"can_link_multiple": False,
"request_id": "123"
}
]}
]
result = client.create_catalogs(catalogs)
update catalogs
name |
type |
default value |
catalogs |
list |
- |
catalogs = [
{
"id": 5787,
"name": "Новое имя списка",
"can_add_elements": True,
"can_link_multiple": False
}
]
result = client.update_catalogs(catalogs)
get elements from catalog
name |
type |
default value |
catalogs_id |
int |
- |
page |
int |
1 |
limit |
int |
250 |
filters |
Optional[dict] |
None |
elements = client.get_catalog_elements(5787, page=3, limit=8)
get element from catalog
element = client.get_catalog_element(5787, 2301)
add elements to catalog
name |
type |
default value |
catalogs_id |
int |
- |
elements |
list |
- |
elements = [
{
"name": "Новый элемент списка",
"custom_fields_values": [
{
"field_id": 14263,
"values": [
{
"value": 1000
}
]
}
]
}
]
result = client.add_elements_to_catalog(5787, elements)
update elements in catalog
name |
type |
default value |
catalogs_id |
int |
- |
elements |
list |
- |
elements = [
{
"id": 986757,
"name": "Новое имя элемента"
},
{
"id": 986753,
"name": "Новое имя элемента 2"
}
]
result = client.update_elements_in_catalog(5787, elements)
get users
name |
type |
default value |
page |
int |
1 |
limit |
list |
250 |
with_role |
bool |
False |
with_group |
bool |
False |
users = client.get_users(page=1, limit=250)
get user
name |
type |
default value |
user_id |
int |
1 |
with_role |
bool |
False |
with_group |
bool |
False |
user = client.get_user(2222, with_role=True, with_group=True)
get webhooks
name |
type |
default value |
distansion |
Optional[str] |
None |
webhooks = client.get_webhooks()
subscribe webhook
name |
type |
default value |
distansion |
str |
- |
settings |
list |
- |
result = client.subscribe_webhook(destination="https://example.test", settings=["add_lead"])
get widgets
name |
type |
default value |
page |
int |
1 |
limit |
int |
250 |
widgets = client.get_widgets(page=3, limit=22)
get widget
name |
type |
default value |
widget_code |
str |
- |
widget = client.get_widget('<widget_code>')
install widget
name |
type |
default value |
widget_code |
str |
- |
**kwargs |
str |
- |
example ={
"login": "example",
"password": "eXaMp1E",
"phones": {
504141: "1039"
},
"script_path": "https://example.com/"
}
result = client.install_widget('<widget_code>', **example)
uninstall widget
name |
type |
default value |
widget_code |
str |
- |
result = client.uninstall_widget('<widget_code>')
get tasks
name |
type |
default value |
page |
int |
1 |
limit |
int |
250 |
filters |
Optional[dict] |
None |
order |
Optional[dict] |
None |
tasks = client.get_tasks(page=1, limit=10, filters={'[updated_at][from]': '<timestamp>'})
get task
name |
type |
default value |
task_id |
int |
- |
task = client.get_task(1288)
add tasks
name |
type |
default value |
tasks |
list |
- |
tasks = [
{
"task_type_id": 1,
"text": "Встретиться с клиентом Иван Иванов",
"complete_till": 1588885140,
"entity_id": 9785993,
"entity_type": "leads",
"request_id": "example"
}
]
result = client.add_tasks(tasks=tasks)
update tasks
name |
type |
default value |
tasks |
list |
- |
tasks = [
{
"id": 4745251,
"task_type_id": 2,
"text": "Новое название для задачи",
"complete_till": 1588885140
},
{
"id": 4747929,
"task_type_id": 1,
"text": "Новое название для задачи 2",
"complete_till": 1588885140
}
]
result = client.update_tasks(tasks=tasks)
execution task
name |
type |
default value |
task_id |
int |
- |
is_completed |
bool |
- |
result |
str |
- |
result = client.execution_task(1288, is_completed=True, result="Удалось связаться с клиентом")
get tasks by entity type (leads|contacts|companies|customers)
name |
type |
default value |
entity_type |
str |
- |
page |
int |
1 |
limit |
int |
250 |
filters |
Optional[dict] |
None |
tags = client.get_tags_by_entity_type('leads', page=1, limit=10)
add tasks for entity type (leads|contacts|companies|customers)
name |
type |
default value |
entity_type |
str |
- |
tags |
list |
- |
tags = [
{
"name": "Tag 1"
},
{
"name": "Tag 2",
"request_id": "my_request_id"
},
{
"name": "Tag 3"
}
]
tags = client.add_tags_for_entity_type('leads', tags=tags)
get custom fields
contacts_cf = client.get_contacts_custom_fields()
leads_cf = client.get_leads_custom_fields()
companies_cf = client.get_companies_custom_fields()
customers_cf = client.get_customers_custom_fields()
customer_segments_cf = client.get_customer_segments_custom_fields()
customer_segments_cf = client.get_customer_segments_custom_fields()
get_catalog_custom_fields = client.get_customer_segments_custom_fields('<catalog_id>')
get custom field
contacts_cf = client.get_contacts_custom_field('<id>')
leads_cf = client.get_leads_custom_field('<id>')
companies_cf = client.get_companies_custom_field('<id>')
customers_cf = client.get_customers_custom_field('<id>')
customer_segments_cf = client.get_customer_segments_custom_field('<id>')
get_catalog_custom_fields = client.get_catalog_custom_field('<catalog_id>', '<id>')
create custom field
contacts_cf = client.create_contacts_custom_field(['<cf>'])
leads_cf = client.create_leads_custom_field(['<cf>'])
companies_cf = client.create_companies_custom_field(['<cf>'])
customers_cf = client.create_customers_custom_field(['<cf>'])
customer_segments_cf = client.create_customer_segments_custom_field(['<cf>'])
get_catalog_custom_fields = client.create_catalog_custom_field('<catalog_id>', ['<cf>'])
update custom field
contacts_cf = client.update_contacts_custom_field(['<cf>'])
leads_cf = client.update_leads_custom_field(['<cf>'])
companies_cf = client.update_companies_custom_field(['<cf>'])
customers_cf = client.update_customers_custom_field(['<cf>'])
customer_segments_cf = client.update_customer_segments_custom_field(['<cf>'])
get_catalog_custom_fields = client.update_catalog_custom_field('<catalog_id>', ['<cf>'])