Package: aiokeepin
Async Python Wrapper for KeepinCRM APIThis is an async Python wrapper for the KeepinCRM API that allows you to interact with the API using simple and convenient methods. The wrapper provides aKeepinClientclass with async methods for making HTTP requests and retrieving data from the API.InstallationYou can install the library using pip:pipinstallaiokeepinUsageTo use the KeepinCRM async Python wrapper, import theKeepinClientclass from the library:fromaiokeepinimportKeepinClientInitializing the ClientCreate an instance of theKeepinClientclass by providing your API key:client=KeepinClient(api_key='YOUR_API_KEY')Making API RequestsTheKeepinClientinstance provides async methods that correspond to the different HTTP request methods (GET,POST,PATCH,PUT,DELETE). Each method returns a dictionary containing the response from the API.GET Request Exampleresponse=awaitclient.get('/clients')print(response)POST Request Exampledata={"email":"pib@example.com","company":"Назва чи ПІБ","lead":True,"source_id":5,"status_id":1,"phones":["+380000000001"],"tag_names":["VIP"],"contacts_attributes":[{"fullname":"Прізвище Імʼя По батькові","phones":["+380000000002"],"custom_fields":[{"name":"Посада","value":"Директор"}]}]}response=awaitclient.post('/clients',data=data)print(response)PATCH Request Exampledata={"email":"new_email@example.com"}response=awaitclient.patch('/clients/{client_id}',data=data)print(response)PUT Request Exampledata={"email":"updated_email@example.com"}response=awaitclient.put('/clients/{client_id}',data=data)print(response)DELETE Request Exampleresponse=awaitclient.delete('/clients/{client_id}')print(response)GET Paginated Items Exampleresponse=awaitclient.get_paginated_items('/clients')Error HandlingIn case of an error response from the KeepinCRM API, an exception will be raised. The exceptions provided by the aiokeepin library inherit from the baseKeepinExceptionclass. There are several specific exceptions available for different types of errors:KeepinStatusError: This exception is raised for non-2xx status codes. It contains thestatus_codeandresponseattributes, providing information about the error.InvalidAPIKeyError: This exception is raised specifically for an invalid API key.ValidationError: This exception is raised for invalid data.NotFoundError: This exception is raised when the requested resource is not found.InternalServerError: This exception is raised for internal server errors.When making API requests, you can handle exceptions using try-except blocks to capture and handle specific types of errors. Here's an example:fromaiokeepin.exceptionsimportKeepinStatusError,InvalidAPIKeyErrortry:response=awaitclient.get('/nonexistent_endpoint')exceptInvalidAPIKeyError:print("Invalid API key provided.")exceptKeepinStatusErrorase:print(f"Error:{e.status_code}-{e.response}")You can customize the exception handling based on your specific needs. By catching the appropriate exceptions, you can handle different error scenarios and provide appropriate error messages or take specific actions. Make sure to refer to the documentation for the KeepinCRM API for more details on the possible error responses and their corresponding status codes.DocumentationFor detailed information on the KeepinCRM API, refer to the official API documentation:KeepinCRM API DocumentationLicenseThis project is licensed under the MIT License. See theLICENSEfile for more information.