Import of leads by API methods in the self-hosted version of Bitrix24

16 November 2018

next article
Alexander Kaviuk

Backend Developer

Alexander Kaviuk
Import of leads by API methods in the self-hosted version of Bitrix24

Lead - irrelevant information (garbage) or a brait

In contrast with the past, the media scene is oversaturated with various offers that may be competitive for your business. Users in the Internet are not also represent a holistic audience: some purposefully look for your product or service, others just get accustomed, and others simply surf sites without buying something. But they are all potentially suitable for your future customers. But all of them need a little help in this.

Each lead: a phone number, an e-mail, any name and other information that relate to a potential client, is very important. Very often, it is these little things that grow into something more. And so, this is LEAD - an entity from which a full-fledged client can grow. Within the framework of CRM Bitrix24, a contact, a company and finally a deal may be converted from a client!

There is no need to explain that leads are a very important link in project management. In this article I will try to describe in detail the methods and aspects of the import of leads in Bitrix24. First of all, it will be useful for developers. But, I am sure, and it will be useful for managers to know these methods and understand their scope and complexity.

The most acute pain

It happens very often that a business “moves” from one CRM to another. In Bitrix24, this is a common practice, since the functionality and cost attract users of other CRM here. It is also a common option when several CRMs work in parallel and data synchronization is necessary. In Bitrix24, there are several options for creation leads in the system:

  1. Manually;

  2. Import from CSV files;

  3. Using web-forms, questionnaires, direct calls or emails.

From my personal experience, I know the situation when the work at the customer was conducted simultaneously in two CRMs. Bitriks24 was new and the task was to transfer there all the clients from the already existing CRM. It is clear that it was inexpedient to do this manually, or more precisely, it is simply impossible. The option of remaking the methods of collecting leads into the right CRM was not considered at all. We stopped on importing from a file, but not through the user interface, but using АРІ.

The customer wanted the file to be uploaded to the server and periodically processed by the crown, but there was no final solution: the conditions changed very often, and along with them the data transfer methods. Only the idea of writing a feature set to save in Bitrix24 remained unchanged.

Custom  solution

Documentation on the functions and methods for working with leads is practically absent. I had to solve the problem by standard methods. And so, the main work happens with the CCrmLead class.

Screenshot.png

We use standard methods GetList, Update i Add. Our task is to get data from the source, to check whether our new database no longer contains such data, and only after that to create a new lead or update an existing one. Before writing this code in Bitrix24, you must create all the fields that will be filled with information from the corresponding fields of another CRM.

Screenshot (1).png

In order to specify the data for the created fields in the script, we need to know its identifier. If you pay attention to the address for editing the desired field “/crm/configs/fields/?mode=edit&entity_id=CRM_LEAD&field_id=UF_CRM_1519634296”, then you can see field_id=UF_CRM_1519634296. To set this field a value “Hobby”, it must be specified in the data array with this key.

If we have a list of 20 user fields, then it is extremely inconvenient to pull out id, looking at addresses. Using the function CCrmLead::GetUserFields($langID = false), you can get an array with information about such fields.

3.png

To get a list of standard fields, you can use CCrmLead::GetFields(). A field "TITLE" is obligatory to create a lead.

At the beginning you may also need put the lead status. Status information can be obtained using the function CcrmLead::GetStatuses().

“Let's go!” (C)

And we will begin. The script that adds the lead with the email “test@test.com” will look like this:

$oLead = new CCrmLead(false); - аргумент показывает или нужно проверять права.
$arFields=array(
   "TITLE"=>'Lead test',
   "EMAIL"=>'test@test.com',
   "STATUS_ID" => 'NEW',
   "UF_CRM_1519634296" => 'Fishing',
   "UF_CRM_1519635704" => 26,
"PERMISSION" => 'IMPORT'
   );
$LEAD_ID=$oLead->Add($arFields, true, array('CURRENT_USER'=>1));

Since the script will be executed in the crown, you need to specify the user the leads will be attached to. In this case, it is the admin. Also, do not forget about the attribute of rights PERMISSION, which will then allow you to edit the Lead data.

We use the following methods:

	
Add(array &$arFields, $bUpdateSearch = true, $options = array())
Update($ID, array &$arFields, $bCompare = true, $bUpdateSearch = true, $options = array())

Conclusion

Bitrix24 has all the tools to work with your business customers. Even if there is any task that is beyond the automatic methods, experienced developers can correct its execution. And in the best case - to create a completely new, but effective logic for your situation.


Similar articles
Apply for a consultation

We will reach out to within 10 minutes