Package: amocrm-api-wrapper
wrapper for amocrm rest apiInstallInstall usingpip...pip install amocrm-api-wrapperUsage=======fromamocrm_apiimportAmoLegacyClient# for login password authfromamocrm_apiimportAmoOAuthClient# for oauthfromdatetimeimportdatetimeclient=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 clientheaders={"IF-MODIFIED-SINCE":f"{date_time}","Content-Type":"application/json",}client.update_session_params(headers)get account infodoc -https://www.amocrm.ru/developers/content/crm_platform/account-infoparams:nametypedefault valuewith_amojo_idboolFalsewith_amojo_rightsboolFalsewith_users_groupsboolFalsewith_task_typesboolFalsewith_versionboolFalsewith_ventity_namesboolFalsewith_datetime_settingsboolFalseaccount_info=client.get_account_info()create leadsdoc -https://www.amocrm.ru/developers/content/crm_platform/leads-api#leads-addparams:nametypedefault valueobjectslist-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 leadsdoc -https://www.amocrm.ru/developers/content/crm_platform/leads-api#leads-editparams:nametypedefault valueobjectslist-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 leaddoc -https://www.amocrm.ru/developers/content/crm_platform/leads-api#lead-detailparams:nametypedefault valuelead_idint-lead=client.get_lead(123)get leadsdoc -https://www.amocrm.ru/developers/content/crm_platform/leads-api#leads-listparams:nametypedefault valuelimitint250pageint1with_paramsOptional[list]NonefiltersOptional[dict]NoneorderOptional[dict]Noneleads=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__toget unsorted leadsdoc -https://www.amocrm.ru/developers/content/crm_platform/unsorted-api#unsorted-listparams:nametypedefault valuelimitint250pageint1filter_by_uidsUnion[str, list, None]Nonefilter_by_pipeline_idUnion[str, list, None]Nonefilter_by_categoryUnion[str, list, None]Noneorder_byOptional[dict]Noneunsorted_leads=client.get_unsorted_leads(limit=10,page=3,filter_by_pipeline_id=[1,2310,8751035])get unsorted lead by uiddoc -https://www.amocrm.ru/developers/content/crm_platform/unsorted-api#unsorted-detailparams:nametypedefault valueuidstr-unsorted_lead=client.get_unsorted_by_uid('ufsigkgdjlk13igmd')create unsorted lead by sipdoc -https://www.amocrm.ru/developers/content/crm_platform/unsorted-api#unsorted-add-sipparams:nametypedefault valuesource_uidstr-source_namestr-metadatadict-conctactdict-leaddict-comapanydict-pipeline_idOptional[int]Nonecreated_atOptional[int]Nonerequest_idOptional[int]Noneunsorted_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 formdoc -https://www.amocrm.ru/developers/content/crm_platform/unsorted-api#unsorted-add-formparams:nametypedefault valuesource_uidstr-source_namestr-metadatadict-conctactdict-leaddict-comapanydict-pipeline_idOptional[int]Nonecreated_atOptional[int]Nonerequest_idOptional[int]Noneunsorted_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 leaddoc -https://www.amocrm.ru/developers/content/crm_platform/unsorted-api#unsorted-acceptparams:nametypedefault valueuidstr-user_idint-status_idint-result=client.accept_unsorted('jkjsoijg2321kgkdu2',2310,4444)decline unsorted leaddoc -https://www.amocrm.ru/developers/content/crm_platform/unsorted-api#unsorted-declineparams:nametypedefault valueuidstr-user_idint-result=client.decline_unsorted('jkjsoijg2321kgkdu2',2310,)link unsorted lead ot another leaddoc -https://www.amocrm.ru/developers/content/crm_platform/unsorted-api#unsorted-linkparams:nametypedefault valueuidstr-user_idint-linkdict-result=client.link_unsorted('jkjsoijg2321kgkdu2',2310,link={"entity_id":93144801,"entity_type":"leads"})get summary unsorted leadsdoc -https://www.amocrm.ru/developers/content/crm_platform/unsorted-api#unsorted-summaryparams:nametypedefault valueuidUnion[str, list, None]Nonecreated_at__fromOptional[str]Nonecreated_at__toOptional[str]Nonepipeline_idUnion[str, list, None]Nonesummary_unsorted=client.get_summary_unsorted()get pipelinesdoc -https://www.amocrm.ru/developers/content/crm_platform/leads_pipelines#pipelines-listpipelines=client.get_pipelines()craete pipelinedoc -https://www.amocrm.ru/developers/content/crm_platform/leads_pipelines#pipelines-addparams:nametypedefault valuenamestr-sortint-is_mainbool-statuseslist-is_unsorted_onboolFalserequest_idOptional[str]Nonepipeline={"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 pipelinedoc -https://www.amocrm.ru/developers/content/crm_platform/leads_pipelines#pipelines-addparams:nametypedefault valuepipeline_idint-namestr-sortint-is_mainbool-is_unsorted_onboolFalsepipeline={"pipeline_id":2310,"name":"Новое название для воронки","is_main":False,"is_unsorted_on":False,"sort":100}result=client.edit_pipeline(**pipeline)delete pipelinedoc -https://www.amocrm.ru/developers/content/crm_platform/leads_pipelines#pipeline-deleteparams:nametypedefault valuepipeline_idint-result=client.delete_pipeline(2310)get statuses by pipelinedoc -https://www.amocrm.ru/developers/content/crm_platform/leads_pipelines#statuses-listparams:nametypedefault valuepipeline_idint-pipeline_statuses=client.get_pipeline_statuses(2310)get pipeline statusdoc -https://www.amocrm.ru/developers/content/crm_platform/leads_pipelines#status-detailparams:nametypedefault valuepipeline_idint-status_idint-pipeline_status=client.get_pipeline_status(2310,123)add statuses to pipelinedoc -https://www.amocrm.ru/developers/content/crm_platform/leads_pipelines#statuses-addparams:nametypedefault valuepipeline_idint-statuseslist-statuses=[{"name":"Новый этап","sort":100,"color":"#fffeb2"},{"name":"Новый этап 2","sort":200,"color":"#fffeb2"}]result=client.add_statuses_to_pipeline(2310,statuses)edit pipeline statusdoc -https://www.amocrm.ru/developers/content/crm_platform/leads_pipelines#statuses-addparams:nametypedefault valuepipeline_idint-status_idint-namestr-sortint-colorstr-result=client.edit_pipeline_status(2310,123,'Новый Этап',sort=500,color="#fffeb2")delete status from pipelinedoc -https://www.amocrm.ru/developers/content/crm_platform/leads_pipelines#status-deleteparams:nametypedefault valuepipeline_idint-status_idint-result=client.delete_status_from_pipeline(2310,123)get contactsdoc -https://www.amocrm.ru/developers/content/crm_platform/contacts-api#contacts-listparams:nametypedefault valuelimitint250pageint1with_paramsOptional[list]NonefiltersOptional[dict]NoneorderOptional[dict]Nonecontacts=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__toget contactdoc -https://www.amocrm.ru/developers/content/crm_platform/contacts-api#contact-detailparams:nametypedefault valuecontact_idint-contact=client.get_contact(123989)create contactsdoc -https://www.amocrm.ru/developers/content/crm_platform/contacts-api#contacts-addparams:nametypedefault valuecontactslist-conctacts=[{"first_name":"Петр","last_name":"Смирнов","custom_fields_values":[{"field_id":271316,"values":[{"value":"Директор"}]}]},{"name":"Владимир Смирнов","created_by":47272}]result=client.create_contacts(contacts)update contactsdoc -https://www.amocrm.ru/developers/content/crm_platform/contacts-api#contacts-editparams:nametypedefault valuecontactslist-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 companiesdoc -https://www.amocrm.ru/developers/content/crm_platform/companies-api#companies-listparams:nametypedefault valuelimitint250pageint1with_paramsOptional[list]NonefiltersOptional[dict]NoneorderOptional[dict]Nonecompanies=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__toget companydoc -https://www.amocrm.ru/developers/content/crm_platform/companies-api#company-detailparams:nametypedefault valuecompany_idint-company=client.get_company(9988)create companiesdoc -https://www.amocrm.ru/developers/content/crm_platform/companies-api#companies-addparams:nametypedefault valuecompanieslist-companies=[{"name":"АО Рога и Копыта","custom_fields_values":[{"field_code":"PHONE","values":[{"value":"+7912322222","enum_code":"WORK"}]}]}]result=client.create_companies(companies)update companiesdoc -https://www.amocrm.ru/developers/content/crm_platform/companies-api#companies-editparams:nametypedefault valuecompanieslist-companies=[{"id":11090825,"name":"Новое название компании","custom_fields_values":[{"field_code":"EMAIL","values":[{"value":"test@example.com","enum_code":"WORK"}]}]}]result=client.update_companies(companies)get catalogsdoc -https://www.amocrm.ru/developers/content/crm_platform/catalogs-api#lists-listparams:nametypedefault valuepageint1limitint250catalogs=client.get_catalogs(page=1,limit=5)get catalogdoc -https://www.amocrm.ru/developers/content/crm_platform/catalogs-api#list-detailparams:nametypedefault valuecatalog_idint1catalog=client.get_catalog(12319)create catalogsdoc -https://www.amocrm.ru/developers/content/crm_platform/catalogs-api#lists-addparams:nametypedefault valuecatalogslist-catalogs=[{"name":"Тестовый список","can_add_elements":True,"can_link_multiple":False,"request_id":"123"}]}]result=client.create_catalogs(catalogs)update catalogsdoc -https://www.amocrm.ru/developers/content/crm_platform/catalogs-api#lists-editparams:nametypedefault valuecatalogslist-catalogs=[{"id":5787,"name":"Новое имя списка","can_add_elements":True,"can_link_multiple":False}]result=client.update_catalogs(catalogs)get elements from catalogdoc -https://www.amocrm.ru/developers/content/crm_platform/catalogs-api#list-elements-listparams:nametypedefault valuecatalogs_idint-pageint1limitint250filtersOptional[dict]Noneelements=client.get_catalog_elements(5787,page=3,limit=8)get element from catalogdoc -https://www.amocrm.ru/developers/content/crm_platform/catalogs-api#list-elements-detailparams:nametypedefault valuecatalogs_idint-element_idint-element=client.get_catalog_element(5787,2301)add elements to catalogdoc -https://www.amocrm.ru/developers/content/crm_platform/catalogs-api#list-elements-addparams:nametypedefault valuecatalogs_idint-elementslist-elements=[{"name":"Новый элемент списка","custom_fields_values":[{"field_id":14263,"values":[{"value":1000}]}]}]result=client.add_elements_to_catalog(5787,elements)update elements in catalogdoc -https://www.amocrm.ru/developers/content/crm_platform/catalogs-api#list-elements-editparams:nametypedefault valuecatalogs_idint-elementslist-elements=[{"id":986757,"name":"Новое имя элемента"},{"id":986753,"name":"Новое имя элемента 2"}]result=client.update_elements_in_catalog(5787,elements)get usersdoc -https://www.amocrm.ru/developers/content/crm_platform/users-api#users-listparams:nametypedefault valuepageint1limitlist250with_roleboolFalsewith_groupboolFalseusers=client.get_users(page=1,limit=250)get userdoc -https://www.amocrm.ru/developers/content/crm_platform/users-api#user-detailparams:nametypedefault valueuser_idint1with_roleboolFalsewith_groupboolFalseuser=client.get_user(2222,with_role=True,with_group=True)get webhooksdoc -https://www.amocrm.ru/developers/content/crm_platform/webhooks-api#webhooks-listparams:nametypedefault valuedistansionOptional[str]Nonewebhooks=client.get_webhooks()subscribe webhookdoc -https://www.amocrm.ru/developers/content/crm_platform/webhooks-api#webhook-subscribeparams:nametypedefault valuedistansionstr-settingslist-result=client.subscribe_webhook(destination="https://example.test",settings=["add_lead"])get widgetsdoc -https://www.amocrm.ru/developers/content/crm_platform/widgets-api#widgets-listparams:nametypedefault valuepageint1limitint250widgets=client.get_widgets(page=3,limit=22)get widgetdoc -https://www.amocrm.ru/developers/content/crm_platform/widgets-api#widget-detailparams:nametypedefault valuewidget_codestr-widget=client.get_widget('<widget_code>')install widgetdoc -https://www.amocrm.ru/developers/content/crm_platform/widgets-api#widget-installparams:nametypedefault valuewidget_codestr-**kwargsstr-example={"login":"example","password":"eXaMp1E","phones":{504141:"1039"},"script_path":"https://example.com/"}result=client.install_widget('<widget_code>',**example)uninstall widgetdoc -https://www.amocrm.ru/developers/content/crm_platform/widgets-api#widget-uninstallparams:nametypedefault valuewidget_codestr-result=client.uninstall_widget('<widget_code>')get tasksdoc -https://www.amocrm.ru/developers/content/crm_platform/tasks-api#tasks-listparams:nametypedefault valuepageint1limitint250filtersOptional[dict]NoneorderOptional[dict]Nonetasks=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__toget taskdoc -https://www.amocrm.ru/developers/content/crm_platform/tasks-api#task-detailparams:nametypedefault valuetask_idint-task=client.get_task(1288)add tasksdoc -https://www.amocrm.ru/developers/content/crm_platform/tasks-api#tasks-addparams:nametypedefault valuetaskslist-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 tasksdoc -https://www.amocrm.ru/developers/content/crm_platform/tasks-api#tasks-editparams:nametypedefault valuetaskslist-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 taskdoc -https://www.amocrm.ru/developers/content/crm_platform/tasks-api#tasks-completeparams:nametypedefault valuetask_idint-is_completedbool-resultstr-result=client.execution_task(1288,is_completed=True,result="Удалось связаться с клиентом")get tasks by entity type (leads|contacts|companies|customers)doc -https://www.amocrm.ru/developers/content/crm_platform/tags-api#tags-listparams:nametypedefault valueentity_typestr-pageint1limitint250filtersOptional[dict]Nonetags=client.get_tags_by_entity_type('leads',page=1,limit=10)add tasks for entity type (leads|contacts|companies|customers)doc -https://www.amocrm.ru/developers/content/crm_platform/tags-api#tags-addparams:nametypedefault valueentity_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 fieldsdoc -https://www.amocrm.ru/developers/content/crm_platform/custom-fields#common-infocontacts_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 fielddoc -https://www.amocrm.ru/developers/content/crm_platform/custom-fields#custom-field-detailcontacts_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 fielddoc -https://www.amocrm.ru/developers/content/crm_platform/custom-fields#custom-fields-addcontacts_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 fielddoc -https://www.amocrm.ru/developers/content/crm_platform/custom-fields#custom-fields-editcontacts_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>'])changelog0.0.12 - add entity notes methods, rename updatecustomers_segments_custom_fields -> update_customers_segments_custom_fields