Used to interact with the site. Available methods: user registration, adding, retrieving, update and delete records.

Where and how to use the API

  1. When client registering  on your site, you need also create an account for it on the Rukovoditel.
  2. When client creating order on your site, you need part of the data insert to Rukovoditel for the reporting.
  3. You want to display on your site some of the public data from a report.
  4. Integration with third-party services. For example, you have an address database, and you want to display them on the map in your own format. Using the API, you can select data from the database and display it using a third-party service. This can be done in real time.

To start using the API, you need to allow access to the API and generate the key. You can do this on the page: Extension - Tools - API.

Please note, the following examples are not intended for use on your application. Each application created in the Rukovoditel has its own unique ID for the Fields and Entities that must be used in the API code.

Adding one or more records (insert)

<?php

$items = array();
$items[] = array(
  'field_338' => 'Test Ticket', //338 - Text field ID
  'field_426' => '2017-12-29', //426 - Field ID of the type "Date with calendar"
  'field_429' => '166,167', //429 - Field ID of the "Dropdown multiselect"
);

$params = array(
  'key' => 'XgDXFsTbNRkMpRq81bBrmRAf56i5oS0oN9bp4jLH', //API key
  'username' => 'admin', //username
  'password' => 'admin', //password
  'action' => 'insert', //action
  'entity_id' => 34, //ID of the entity to which the record will be added
  'items' => $items, //array of records
);
 						                                    
$ch = curl_init('http://localhost/rukovoditel/api/rest.php'); //API Url
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);			
$result = curl_exec($ch);
curl_close($ch);

if($result)
{
  $result = json_decode($result,true);
  
  print_r($result);
}

 

If successful, returns the ID of the added records:

Array
(
    [status] => success
    [data] => Array
        (
            [id] => 119
        )

)

 

In case of an error, returns the text of the error:

Array
(
    [status] => error
    [error_code] => 
    [error_message] => field_429 not exist in entity 34
)

 

Поле Описание
key API key. Generate on the page: Extension - Tools - API.
username The username who has the access to perform the action.
password The user's password.
action The action to be performed.
entity_id The ID of the entity for which the action is performed.
items An array of records, including the fields of the record.
  parent_item_id - an optional field is required if the entry is added to the parent record.
 

field_X - the field to add, where X is the field ID. The field ID can be found on the "Field Configuration" page. This field takes a value as a string.

Date
For the "date" field type, use the format YYYY-MM-DD.

Drop-down list
For the field type "Drop-down list" use the option ID, which can be found on the "Options" page for each field. If you are using a Global List, use the option ID from the Global List. If there is a list with multiple values, enter them separated by commas.

Attachments
To transfer attachments via the API, specify an http link to the file in the field value. You can add multiple urls separated by commas.

 

New User Registration (insert)

It works in the same way as adding a new entry and has mandatory fields for user registration.

<?php

$items = array();
$items[] = array(
  'group_id' => 4, //4 - User group ID
  'firstname' => 'Сергей',
  'lastname' => 'Харчишин',
  'username' => 'admin',
  'email' => 'support@rukovoditel.net',
  'password' => '', //If not specified, it will be generated automatically.
);

$params = array(
  'key' => 'XgDXFsTbNRkMpRq81bBrmRAf56i5oS0oN9bp4jLH',  
  'username' => 'manager',
  'password' => 'manager',
  'action' => 'insert',
  'entity_id' => 1,
  'notify' =>true, //A notification will be sent to the user.
  'login_url' => 'http://localhost/rukovoditel/index.php',
  'items' => $items,
);
 						                                    
$ch = curl_init('http://localhost/rukovoditel/api/rest.php');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);			
$result = curl_exec($ch);
curl_close($ch);

if($result)
{
  $result = json_decode($result,true);
  
  print_r($result);
}

 

Поле Описание
entity_id Must be 1
notify To send a notification to the user's mail (true/false)
login_url The login link is added to the user notification.
items An array of records, including the fields of the record.
 

field_X - the field to add, where X is the field ID. The field ID can be found on the "Field Configuration" page. This field takes a value as a string.

Обязательные поля Описание
group_id Group ID for the user.
You can find out on the "User groups" page.
firstname First Name
lastname Last Name
username Username
email Email
password Password. Can be left blank, will be generated automatically.

 

Selecting records (select) 

<?php

$params = array(
  'key' => 'XgDXFsTbNRkMpRq81bBrmRAf56i5oS0oN9bp4jLH',  
  'username' => 'admin',
  'password' => 'admin',
  'action' => 'select',
  'entity_id' => 34, //The ID of the entity from which records will be selected
  'limit' => 0, //If not specified, all rows are selected
  'select_fields' => '338,388', //ID fields, the values of which will be selected
  'reports_id' => 370, //The report ID whose filters will be applied to the sample
  'filters' => array(
    '159'=>'2018-05-10,2018-05-16', //Filter by date 'from,to'. You can specify one of the values, for example' 2018-05-10,', and leave the second empty.
    '157'=>array('value'=>37,'condition'=>'include'), //Filter by field type list. condition can be include/exclude
    '203' => '>30' //Filter by numeric field
    '203' => array('condition'=>'not_empty_value'), //empty_value or not_empty_value - empty or non-empty field values  
    '158' => array('value'=>'keywords','condition'=>'search'), //search by value 
    //System fields (id, parent_item_id, date_added) can also be used as filters
    'id' => '13,14',
  )
);
 						                                    
$ch = curl_init('http://localhost/rukovoditel/api/rest.php');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);			
$result = curl_exec($ch);
curl_close($ch);

if($result)
{
  $result = json_decode($result,true);

  print_r($result);
}

 

Поле Описание
entity_id The ID of the entity from which records will be selected
limit If not specified, all rows are selected
select_fields The ID of the fields whose values will be selected.
Enter an ID separated by a comma. If not specified, values from all fields are selected.
reports_id The report ID, the filters and sorting of which will be applied to the selection.
If not specified, all records are selected.
filters New option in version 2.2. Optional field. Allows you to use custom filters when you select records.

On successful execution, returns an array of records:

Array
(
    [status] => success
    [data] => Array
        (
            [0] => Array
                (
                    [id] => 112
                    [date_added] => 01/15/2018 10:42
                    [created_by] => Kharchishin Sergey
                    [338] => Заявка 6
                    [388] => Новая
                )

            [1] => Array
                (
                    [id] => 111
                    [date_added] => 01/15/2018 10:42
                    [created_by] => Kharchishin Sergey
                    [338] => Заявка 5
                    [388] => Новая
                )

            [2] => Array
                (
                    [id] => 110
                    [date_added] => 01/15/2018 10:41
                    [created_by] => Kharchishin Sergey
                    [338] => Заявка 4
                    [388] => Новая
                )

        )

)

 

Update records

<?php

$data = array(
  'field_235' => '9,10,11',
);

$params = array(
  'key' => 'MjBm7iKWaEubxvLvVW1lF5HFbrWzOFILh216iGKJ',  
  'username' => 'admin',
  'password' => 'admin',
  'action' => 'update',
  'entity_id' => 21,
  'data' => $data,
  'update_by_field' => ['field_156'=>34],
);
						                                    
$ch = curl_init('http://localhost/rukovoditel/product_2.5/api/rest.php');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);			
$result = curl_exec($ch);
curl_close($ch);

if($result)
{
  $result = json_decode($result,true);  
}

 

Field Description
entity_id Entity ID which needs to update
data Array of fields which need to update. System fields can be updated:
created_by, parent_item_id, password
update_by_field The field by which the record will be updated. You can update a record by ID or by field value, such as updating all records with a specific status.
Примеры  
'update_by_field' => ['id'=>37] Update record where ID = 37
'update_by_field' => ['id'=>[37,38]], Update record where ID 37  and  38
'update_by_field' => ['field_156'=>34] Update records where field number 156 is set to 34

Delete records

<?php
 
$params = array(
  'key' => 'MjBm7iKWaEubxvLvVW1lF5HFbrWzOFILh216iGKJ',  
  'username' => 'admin',
  'password' => 'admin',
  'action' => 'delete',
  'entity_id' => 21, 
  'delete_by_field' => ['id'=>40],
);
 						                                    
$ch = curl_init('http://localhost/rukovoditel/product_2.5/api/rest.php');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);			
$result = curl_exec($ch);
curl_close($ch);

if($result)
{
  $result = json_decode($result,true);
}

 

Field Description
entity_id ID of the entity from which the data will be deleted
delete_by_field The field on which the record will be deleted. You can delete a record by ID or by field value, for example, delete all records with a specific status.
Примеры  
'delete_by_field' => ['id'=>37] Delete records where ID = 37
'delete_by_field' => ['id'=>[37,38]], Delete record where ID 37 and 38
'delete_by_field' => ['field_156'=>34] Delete records where field number 156 is set to 34