Insert
Adding one record example:
<?php
$item = 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' => $item, //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
)
Field | Description |
---|---|
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 Drop-down list Attachments |
Example of adding multiple records:
$items = [];
$items[] = array(
'field_338' => 'Test Ticket 1', //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"
);
$items[] = array(
'field_338' => 'Test Ticket 2', //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
);