API for free CRM





Less than a year ago, we introduced a free CRM system integrated with a free PBX. During this time, 14,000 companies and 64,000 employees have used it.

We currently offer an open API where most of the ZCRM functions are available. The API allows you to use CRM for any sales channel.

Below we will briefly describe the work with the API and the available functionality. There is also a simple but useful and working example: a script for creating a lead from a form on a website.



Briefly about free CRM



Let's refrain from explaining what CRM is. Free CRM Zadarma supports all standard functions of storing customer data. The information is saved in the customer's feed. Also, in addition to information about clients, a convenient task manager is available with a display for every taste (calendar, kanban, list). All this is available for 50+ employees and is fully integrated with telephony (including calls from the browser using WebRTC technology).



What does free mean? There are no tariffs or ZCRM services to pay for. The only thing you need to pay for is for phone calls and numbers (for special rates, for example, the monthly fee for a Moscow number is 95 rubles or for London, 1 euro). And if there are almost no calls? You almost don't need to pay.

Free CRM is active while free PBX Zadarma is active. After registration, the PBX is active for 2 weeks, in the future it is necessary to replenish the account with any amount 1 time in 3 months. It is difficult to imagine an office that needs CRM and PBX, but does not need a number or calls at all.



Why do you need an API for free CRM



The development of ZCRM does not stop for a minute, a lot of large and small functions have appeared. But we understand that in order to present a truly functional system, and not just a smart address book, it is not enough to integrate with telephony.

The more contacts with the client the better and the contacts can be very different. Thanks to the API, you can automatically enter (or, on the contrary, get) information about the client / lead and tasks without any problems. Thanks to this, it becomes possible to connect any channels of communication with customers and any other automation systems.

Thanks to the API, free ZCRM can be used in any way, in whole or in part. For example, as a convenient interface for working with a corporate customer base, or as a simple convenient planner.

Below is an example of such a channel - connecting to the CRM of the lead form on the site. Later on the website we will give other examples, for example, creating a task to call back a client (delayed call).



Basic ZCRM API Methods



Since there are 37 methods available in the ZCRM API, we will refrain from describing all of them, we will describe only their main groups with examples.

A complete list with examples is available on the website in the description of the CRM API .



You can work with the following groups of methods:

  • Clients (general list, separate selections, editing, deleting)
  • Client tags and additional properties
  • Customer feed (view, edit, delete records in customer feeds)
  • Client's employees (since the client is usually a legal entity, he may have many employees)
  • Tasks (all functionality for working with tasks)
  • Leads (similar to all functions)
  • RM users (displaying a list of users, their rights, settings, contacts and working hours)
  • Calls (returns the call list)




Since the existing Zadarma API structure is used, libraries for it are already available on Github in PHP, C #, Python.



API usage example



The simplest yet most useful example is creating a lead from a form. To minimize code, this example contains only the basic lead data. A similar example, but already with comments from the client (usually present in every form) is available on the blog on the site. The script examples are written in PHP without frameworks and therefore are easy to embed.

An example of a html form for creating a lead:



<form method="POST" action="/zcrm_leads">
   <label for="name">Name:</label>
   <br>
   <input type="text" id="name" name="name" value="">
   <br>
   <label for="phone">Phone:</label><br>
   <input type="text" id="phone" name="phones[0][phone]" value="">
   <br>
   <label for="phone">Email:</label><br>
   <input type="text" id="email" name="contacts[0][value]" value="">
   <br>
   <br>
   <input type="submit" value="Submit">
</form>




This form is extremely simple so as not to overload the article. It has no design, no captcha, no comment field. A version with a comment field is available on our blog (a comment is added to the customer's feed after creating a lead).



And the actual PHP example for creating a lead with data from a form:



<?php
$postData = $_POST;
if ($postData) {
   if (isset($postData['phones'], $postData['phones'][0], $postData['phones'][0]['phone'])) {
       $postData['phones'][0]['type'] = 'work';
   }
   if (isset($postData['contacts'], $postData['contacts'][0], $postData['contacts'][0]['value'])) {
       $postData['contacts'][0]['type'] = 'email_work';
   }
   $params = ['lead' => $postData];
   $params['lead']['lead_source'] = 'form';

   $leadData = makePostRequest('/v1/zcrm/leads', $params);
   var_dump($leadData);
}
exit();

function makePostRequest($method, $params)
{
   //  userKey  secret     
   $userKey = '';
   $secret = '';
   $apiUrl = 'https://api.zadarma.com';

   ksort($params);

   $paramsStr = makeParamsStr($params);
   $sign = makeSign($paramsStr, $method, $secret);

   $curl = curl_init();
   curl_setopt($curl, CURLOPT_URL, $apiUrl . $method);
   curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
   curl_setopt($curl, CURLOPT_POST, true);
   curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
   curl_setopt($curl, CURLOPT_POSTFIELDS, $paramsStr);
   curl_setopt($curl, CURLOPT_HTTPHEADER, [
       'Authorization: ' . $userKey . ':' . $sign
   ]);

   $response = curl_exec($curl);
   $error = curl_error($curl);

   curl_close($curl);

   if ($error) {
       return null;
   } else {
       return json_decode($response, true);
   }
}

/**
* @param array $params
* @return string
*/
function makeParamsStr($params)
{
   return http_build_query($params, null, '&', PHP_QUERY_RFC1738);
}

/**
* @param string $paramsStr
* @param string $method
* @param string $secret
*
* @return string
*/
function makeSign($paramsStr, $method, $secret)
{
   return base64_encode(
       hash_hmac(
           'sha1',
           $method . $paramsStr . md5($paramsStr),
           $secret
       )
   );
}





As you can see, working with the API is quite simple, plus there are examples of working in PHP , C # , Python . Thus, without any problems, you can fit a simple free CRM into any workflow, getting automation with little blood.

ZCRM is constantly evolving and almost all new functions will be available, including through the API.

We also invite you to integrate your existing system systems with free CRM and Zadarma PBX.



All Articles