Rest API
Used to interact with the site. Available methods: user registration, adding and retrieving records.
Where and how to use the API:
- When client registering on your site, you need also create an account for it on the Prosto System 24/7.
- When client creating order on your site, you need part of the data insert to Prosto System 24/7 for the reporting.
- You want to display on your site some of the public data from a report.
- 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 Prosto System 24/7 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/prostosystem/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);
}
Array
(
[status] => success
[data] => Array
(
[id] => 119
)
)
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.
For the “date” field type, use the format YYYY-MM-DD. 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. |
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' => 'Viktor',
'lastname' => 'Pavlov',
'username' => 'admin',
'email' => 'support@prostosystem.com',
'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/prostosystem/index.php',
'items' => $items,
);
$ch = curl_init('http://localhost/prostosystem/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.
|
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
);
$ch = curl_init('http://localhost/prostosystem/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. |
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] => Pavlov Viktor
[338] => Заявка 6
[388] => Новая
)
[1] => Array
(
[id] => 111
[date_added] => 01/15/2018 10:42
[created_by] => Pavlov Viktor
[338] => Заявка 5
[388] => Новая
)
[2] => Array
(
[id] => 110
[date_added] => 01/15/2018 10:41
[created_by] => Pavlov Viktor
[338] => Заявка 4
[388] => Новая
)
)
)
Leave A Comment?
You must be logged in to post a comment.