Skip to main content

How to properly develop your own REST methods for on-premise Bitrix24

During one of our recent implementations, CRM Bitrix24 was used as a backend for another external system - for a student's account. Through an account interface, students can apply for training in the chosen course, upload the necessary documents, monitor the status of their application, pay tuition bills, and also interact with their curators. All this is very deeply integrated with Bitrix24 business processes. For such a deep integration of Bitrix with a third-party system, we lacked standard REST methods - the logic for using requests became too complicated and confusing.

Before we were hired for the project, a lot of logic had already been implemented on the side of the student's account, which made it too closely related to Bitrix24 and violated the principles of SOLID development.

The solution was to write our own REST methods. Of course, it may seem to someone that one could simply create a public page that will return the result to an external request in the form of a JSON object, but this approach is wrong for several reasons:

1. It may not be safe.

2. This is not convenient, since in the external system during integration you will have to write requests to standard REST methods and to such pages in different ways.

Fortunately, the Bitrix24 developers have provided the ability to write their own REST methods to extend the standard ones. It's very simple. We write our own provider class for our methods:

And we register it in php_interface by hanging an event handler:

Everything is ready.

The CustomRestProvider class contains the OnRestServiceBuildDescription method, which is called on the event of the same name. This method returns an array whose keys are your new scope and whose values are an array of methods of this scope. You can work with scope in the same way as with standard ones.

Now we can access the custom.hello.world method just like standard REST methods. Don't forget to give new scope permissions to your webhooks!

Comments

Popular posts from this blog

How to add a custom activity type in Bitrix24 CRM

During one of our recent self-hosted Bitrix24 implementations, we had the task of adding a new type of Activity to CRM - something between a Call Activity and a Visit Activity. The customer wanted this new Activity to be able to participate in CRM reports and filters. To begin with, it was necessary to add a link to a new Activity type in the CRM entity card. We found out that the crm.timeline component is responsible for the output of this part of the interface. In particular, its template.php contains a list of displayed links to case types. For example, for a call, something like: Accordingly, as we can see, this is a regular link with the data parameter item-item-id. So we can add ours, with our own unique data-item-id. As you can see, the href for the link is set as "#" - clicking on this link is processed by the JS code from the script.js of this component. Indeed, the BX.CrmTimelineMenuBar function is responsible for this.processItemSelection().

How to setup server for Bitrix24 on AWS EC2

How to сreate AWS Lambda Layer with Zeep Library

Python Zeep library designed to work with SOAP - services. Zeep is a pure-python module. However the lxml dependency does contain C code since it uses libxml2 and libxslt. So the Zeep library can not be deployed into the Lambda Layer without some tricks. In one of my Serverless projects, I needed to use this library, and I found such a way to deploy it into the Layer: