Package: bitrix24-python3-client
bitrix24-python3-clientA tiny Python3 client to make requests of Bitrix24 API.RequirementsDepends on the following packages (seerequirements.txt):requestsInstallationFirst of all install necessary dependencies (see above) andbitrix24-python3-clientitself:$pipinstallbitrix24-python3-clientGetting startedThe client is tiny therefore it'seasy to use. All what you need to start it'sdomain name,client IDandclient secret keyof your application (if you already haveaccessandrefresh tokensyou can pass it as optional kwargs into the Bitrix24 client).First of all you need tocreate Bitrix24 instanceto work with. Let's create it as follows (we will consider basic configuration without existing tokens):# Import Bitrix24 client to work with>>>frombitrix24importBitrix24# Create instance with basic configuration>>>bx24=Bitrix24('your-domain.bitrix24.com','your.client.id','your_client_secret')Looks like not bad, but you can't do anything yet. You must fill out all required attributes of the Bitrix24 client. To do that we canrequest itdirectly from a Bitrix24 server (orpass as optional kwargs for the Bitrix24 client before creating an instance):# Get authorization URL to request authorization code via browser>>>bx24.resolve_authorize_endpoint()'https://your-domain.bitrix24.com/oauth/authorize/?client_id=your.client.id&response_type=code'# Request tokens to interact with Bitrix24 API>>>bx24.request_tokens('requested_authorization_code')You cancheck if all's wellby following command which simply return dict of current tokens:# Get current access and refresh tokens>>>bx24.get_tokens(){'access_token':'requested_access_token','refresh_token':'requested_refresh_token'}Pay attention!Your tokens have 1 hour lifecycle by default therefore you may need torefresh tokensat the expiration of this time:# Refresh current tokens (refresh token required)>>>bx24.refresh_tokens()# Check whether old tokens was replaced>>>bx24.get_tokens(){'access_token':'new_access_token','refresh_token':'new_refresh_token'}Okay, all the preparation works done and now we canmake API calls to a Bitrix24 server(don't forget to check theclient_endpointattribute of the Bitrix24 client whether it exists).Make asingle call:# The following example needs the `user` permission>>>bx24.call_method('user.get',{'ID':1}){'result':{...}}Make abatch call(many single calls by one request):# The following example needs the `user` and `department` permissions>>>bx24.call_batch({...'get_user':('user.current',{}),# or 'user.current'...'get_department':{...'method':'department.get',...'params':{'ID':'$result[get_user][UF_DEPARTMENT]'}...}...}){'result':{'result':{...}}}Make anevent binding(shortcut for theevent.bindmethod):>>>bx24.call_bind('OnAppUpdate','https://example.com/'){'result':{...}}Make anevent unbinding(shortcut for theevent.unbindmethod):>>>bx24.call_unbind('OnAppUpdate','https://example.com/'){'result':{...}}Get closer to webhooksAll methods described above come in handy when you develop applications or similar tricky things. However, sometimes will be enough to call awebhook- simplified version of rest-events and rest-teams that does not require a application to write.So, let's create a simple webhook!If you need to make webhook callsonly, the following configuration will fit (in other case see verbose configuration above):# Import Bitrix24 client to work with>>>frombitrix24importBitrix24# Create instance with basic configuration>>>bx24=Bitrix24('your-domain.bitrix24.com',user_id=1)Make awebhook call:# You can pass a dict of params as third argument>>>bx24.call_webhook('profile','xxxxxxxxxxxxxxxx'){'result':{...}}That's end of quick introduction. To learn details,explore source code(believe me those code is such simple as this client). Good luck!StatusThe client is already ready to use (v0.3.3).I'll probably add more functionality later. This is what I need right now.Copyright and LicenseCopyright (c) 2017-2019 Yuriy Rabeshko. Code released under the MIT license.