πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
Book a DemoInstallSign in
Socket

amocrm-api-wrapper

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amocrm-api-wrapper

Amocrm api wrapper v4

0.0.19
PyPI
Maintainers
1

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 = AmoLegacyClient('<login>', '<password>', '<crm_url>')
client = AmoOAuthClient('<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

  • doc - https://www.amocrm.ru/developers/content/crm_platform/account-info
  • params:
nametypedefault value
with_amojo_idboolFalse
with_amojo_rightsboolFalse
with_users_groupsboolFalse
with_task_typesboolFalse
with_versionboolFalse
with_ventity_namesboolFalse
with_datetime_settingsboolFalse
account_info = client.get_account_info()

create leads

nametypedefault value
objectslist-
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

nametypedefault value
objectslist-
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

nametypedefault value
lead_idint-
lead = client.get_lead(123)

get leads

nametypedefault value
limitint250
pageint1
with_paramsOptional[list]None
filtersOptional[dict]None
orderOptional[dict]None
leads = client.get_leads(limit=10, page=3, filters={'updated_at__from': '<timestamp>', 'updated_at__to': '<timestamp>'})
# for any timestamp fields like created_at, updated_at, closed_at u need to user __ like created_at__from, created_at__to

get unsorted leads

nametypedefault value
limitint250
pageint1
filter_by_uidsUnion[str, list, None]None
filter_by_pipeline_idUnion[str, list, None]None
filter_by_categoryUnion[str, list, None]None
order_byOptional[dict]None
unsorted_leads = client.get_unsorted_leads(limit=10, page=3, filter_by_pipeline_id=[1, 2310, 8751035])

get unsorted lead by uid

nametypedefault value
uidstr-
unsorted_lead = client.get_unsorted_by_uid('ufsigkgdjlk13igmd')

create unsorted lead by sip

nametypedefault value
source_uidstr-
source_namestr-
metadatadict-
conctactdict-
leaddict-
comapanydict-
pipeline_idOptional[int]None
created_atOptional[int]None
request_idOptional[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

nametypedefault value
source_uidstr-
source_namestr-
metadatadict-
conctactdict-
leaddict-
comapanydict-
pipeline_idOptional[int]None
created_atOptional[int]None
request_idOptional[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

nametypedefault value
uidstr-
user_idint-
status_idint-
result = client.accept_unsorted('jkjsoijg2321kgkdu2', 2310, 4444)

decline unsorted lead

nametypedefault value
uidstr-
user_idint-
result = client.decline_unsorted('jkjsoijg2321kgkdu2', 2310,)
nametypedefault value
uidstr-
user_idint-
linkdict-
result = client.link_unsorted('jkjsoijg2321kgkdu2', 2310, link={
    "entity_id": 93144801,
    "entity_type": "leads"
})

get summary unsorted leads

nametypedefault value
uidUnion[str, list, None]None
created_at__fromOptional[str]None
created_at__toOptional[str]None
pipeline_idUnion[str, list, None]None
summary_unsorted = client.get_summary_unsorted()

get pipelines

pipelines = client.get_pipelines()

craete pipeline

nametypedefault value
namestr-
sortint-
is_mainbool-
statuseslist-
is_unsorted_onboolFalse
request_idOptional[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

nametypedefault value
pipeline_idint-
namestr-
sortint-
is_mainbool-
is_unsorted_onboolFalse
pipeline = {
    "pipeline_id": 2310,
    "name": "НовоС Π½Π°Π·Π²Π°Π½ΠΈΠ΅ для Π²ΠΎΡ€ΠΎΠ½ΠΊΠΈ",
    "is_main": False,
    "is_unsorted_on": False,
    "sort": 100
}
result = client.edit_pipeline(**pipeline)

delete pipeline

nametypedefault value
pipeline_idint-
result = client.delete_pipeline(2310)

get statuses by pipeline

nametypedefault value
pipeline_idint-
pipeline_statuses = client.get_pipeline_statuses(2310)

get pipeline status

nametypedefault value
pipeline_idint-
status_idint-
pipeline_status = client.get_pipeline_status(2310, 123)

add statuses to pipeline

nametypedefault value
pipeline_idint-
statuseslist-
statuses = [
    {
        "name": "Новый этап",
        "sort": 100,
        "color": "#fffeb2"
    },
    {
        "name": "Новый этап 2",
        "sort": 200,
        "color": "#fffeb2"
    }
]
result = client.add_statuses_to_pipeline(2310, statuses)

edit pipeline status

nametypedefault value
pipeline_idint-
status_idint-
namestr-
sortint-
colorstr-
result = client.edit_pipeline_status(2310, 123, 'Новый Π­Ρ‚Π°ΠΏ', sort=500, color="#fffeb2")

delete status from pipeline

nametypedefault value
pipeline_idint-
status_idint-

result = client.delete_status_from_pipeline(2310, 123)

get contacts

nametypedefault value
limitint250
pageint1
with_paramsOptional[list]None
filtersOptional[dict]None
orderOptional[dict]None

contacts = client.get_contacts(limit=10, page=3, filters={'updated_at__from': '<timestamp>', 'updated_at__to': '<timestamp>'})
# for any timestamp fields like created_at, updated_at, closed_at u need to user __ like created_at__from, created_at__to

get contact

nametypedefault value
contact_idint-

contact = client.get_contact(123989)

create contacts

nametypedefault value
contactslist-
conctacts = [
    {
        "first_name": "ΠŸΠ΅Ρ‚Ρ€",
        "last_name": "Π‘ΠΌΠΈΡ€Π½ΠΎΠ²",
        "custom_fields_values": [
            {
                "field_id": 271316,
                "values": [
                    {
                        "value": "Π”ΠΈΡ€Π΅ΠΊΡ‚ΠΎΡ€"
                    }
                ]
            }
        ]
    },
    {
        "name": "Π’Π»Π°Π΄ΠΈΠΌΠΈΡ€ Π‘ΠΌΠΈΡ€Π½ΠΎΠ²",
        "created_by": 47272
    }
]
result = client.create_contacts(contacts)

update contacts

nametypedefault value
contactslist-
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

nametypedefault value
limitint250
pageint1
with_paramsOptional[list]None
filtersOptional[dict]None
orderOptional[dict]None

companies = client.get_companies(limit=10, page=3, filters={'updated_at__from': '<timestamp>', 'updated_at__to': '<timestamp>'})
# for any timestamp fields like created_at, updated_at, closed_at u need to user __ like created_at__from, created_at__to

get company

nametypedefault value
company_idint-

company = client.get_company(9988)

create companies

nametypedefault value
companieslist-
companies = [
    {
        "name": "АО Π ΠΎΠ³Π° ΠΈ ΠšΠΎΠΏΡ‹Ρ‚Π°",
        "custom_fields_values": [
            {
                "field_code": "PHONE",
                "values": [
                    {
                        "value": "+7912322222",
                        "enum_code": "WORK"
                    }
                ]
            }
        ]
    }
]
result = client.create_companies(companies)

update companies

nametypedefault value
companieslist-
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

nametypedefault value
pageint1
limitint250
catalogs = client.get_catalogs(page=1, limit=5)

get catalog

nametypedefault value
catalog_idint1
catalog = client.get_catalog(12319)

create catalogs

nametypedefault value
catalogslist-
catalogs = [
    {
        "name": "ВСстовый список",
        "can_add_elements": True,
        "can_link_multiple": False,
        "request_id": "123"
    }
]}
]
result = client.create_catalogs(catalogs)

update catalogs

nametypedefault value
catalogslist-
catalogs = [
    {
        "id": 5787,
        "name": "НовоС имя списка",
        "can_add_elements": True,
        "can_link_multiple": False
    }
]
result = client.update_catalogs(catalogs)

get elements from catalog

nametypedefault value
catalogs_idint-
pageint1
limitint250
filtersOptional[dict]None
elements = client.get_catalog_elements(5787, page=3, limit=8)

get element from catalog

nametypedefault value
catalogs_idint-
element_idint-
element = client.get_catalog_element(5787, 2301)

add elements to catalog

nametypedefault value
catalogs_idint-
elementslist-
elements = [
    {
        "name": "Новый элСмСнт списка",
        "custom_fields_values": [
            {
                "field_id": 14263,
                "values": [
                    {
                        "value": 1000
                    }
                ]
            }
        ]
    }
]
result = client.add_elements_to_catalog(5787, elements)

update elements in catalog

nametypedefault value
catalogs_idint-
elementslist-
elements = [
    {
        "id": 986757,
        "name": "НовоС имя элСмСнта"
    },
    {
        "id": 986753,
        "name": "НовоС имя элСмСнта 2"
    }
]
result = client.update_elements_in_catalog(5787, elements)

get users

nametypedefault value
pageint1
limitlist250
with_roleboolFalse
with_groupboolFalse
users = client.get_users(page=1, limit=250)

get user

nametypedefault value
user_idint1
with_roleboolFalse
with_groupboolFalse
user = client.get_user(2222, with_role=True, with_group=True)

get webhooks

nametypedefault value
distansionOptional[str]None
webhooks = client.get_webhooks()

subscribe webhook

nametypedefault value
distansionstr-
settingslist-
result = client.subscribe_webhook(destination="https://example.test", settings=["add_lead"])

get widgets

nametypedefault value
pageint1
limitint250
widgets = client.get_widgets(page=3, limit=22)

get widget

nametypedefault value
widget_codestr-
widget = client.get_widget('<widget_code>')

install widget

nametypedefault value
widget_codestr-
**kwargsstr-
example ={
    "login": "example",
    "password": "eXaMp1E",
    "phones": {
        504141: "1039"
    },
    "script_path": "https://example.com/"
}
result = client.install_widget('<widget_code>', **example)

uninstall widget

nametypedefault value
widget_codestr-
result = client.uninstall_widget('<widget_code>')

get tasks

nametypedefault value
pageint1
limitint250
filtersOptional[dict]None
orderOptional[dict]None
tasks = client.get_tasks(page=1, limit=10, filters={'updated_at__from': '<timestamp>', 'updated_at__to': '<timestamp>'})
# for any timestamp fields like created_at, updated_at, closed_at u need to user __ like created_at__from, created_at__to

get task

nametypedefault value
task_idint-
task = client.get_task(1288)

add tasks

nametypedefault value
taskslist-
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

nametypedefault value
taskslist-
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

nametypedefault value
task_idint-
is_completedbool-
resultstr-
result = client.execution_task(1288, is_completed=True, result="Удалось ΡΠ²ΡΠ·Π°Ρ‚ΡŒΡΡ с ΠΊΠ»ΠΈΠ΅Π½Ρ‚ΠΎΠΌ")

get tasks by entity type (leads|contacts|companies|customers)

nametypedefault value
entity_typestr-
pageint1
limitint250
filtersOptional[dict]None
tags = client.get_tags_by_entity_type('leads', page=1, limit=10)

add tasks for entity type (leads|contacts|companies|customers)

nametypedefault value
entity_typestr-
tagslist-
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>'])

changelog

  • 0.0.18 - add filter_ids get_leads and _get_entities method
  • 0.0.12 - add entity notes methods, rename updatecustomers_segments_custom_fields -> update_customers_segments_custom_fields

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts