API - Schedule Save¶
API Schedule Save is used to save the schedule (opening hours) of the PBX elements.
API URL¶
https://[YOUR-PBX-URL]/api/schedule
The data is transmitted via POST or GET and must be of the form:¶
Array
(
[action] => save
[data] => Array
(
[element_type] => project
[schedule_type] => weekdays
[schedule_data] => Array
(
[0] => Array
(
[element_id] => 1
[day] => 1
[data] => Array
(
[0] => Array
(
[start] => 09:00:00
[end] => 18:00:00
)
)
[break_interval] =>
[break_message] =>
[welcome_message] =>
[ns_welcome_message] =>
[closed_message] =>
[closed_gosub] =>
)
[1] => Array
(
[element_id] => 1
[day] => 2
[data] => Array
(
[0] => Array
(
[start] => 09:00:00
[end] => 17:00:00
)
)
[break_interval] =>
[break_message] =>
[welcome_message] =>
[ns_welcome_message] =>
[closed_message] =>
[closed_gosub] =>
)
)
)
[api_hash] => 07112231a9c89f5b108af08608a97b07
)
The action parameter must have the value save.
The data parameter must contain:
- element_type with one of the values: project, inbound_route, contact, user, ivr_menu, pbx_queue
- schedule_type with the value weekdays or custom
- element_id: required, the ID of the element (it must exist and be active)
- day: required for weekdays: 0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday
- date: required for custom, format Y-m-d; new intervals must be in the future
- data: the list of intervals in the day, each with start and end (format H:i:s, end greater than start; 00:00:00 - 00:00:00 = closed all day) and optionally key (the number of the interval in the day) or delete = 1 (deletes the interval with that key)
- break_interval (format HH:MM-HH:MM) and break_message: optional, sent together
- welcome_message, ns_welcome_message, closed_message (audio files) and closed_gosub: optional
An interval with an existing key is updated, one without key is added. For weekdays, an interval sent without id / key that already exists with the same start and end on that day is recognised and updated, not duplicated.
Rows with errors are ignored, the valid ones are saved; if there are errors, the response has has_error = true and a single message starting with Errors saving schedule:.
HTTP Headers:¶
Content-Type: application/json Authorization: Bearer <token>
Example of parameter generation:
$params = [
'action' => 'save',
'data' => [
'element_type' => 'project',
'schedule_type' => 'weekdays',
'schedule_data' => [
[
'element_id' => 1,
'day' => 1,
'data' => [
[
//'id' => 2,
//'key' => 1,
'start' => '09:00:00',
'end' => '18:00:00'
]
],
'break_interval' => '',
'break_message' => '',
'welcome_message' => '',
'ns_welcome_message' => '',
'closed_message' => '',
'closed_gosub' => ''
],
[
'element_id' => 1,
'day' => 2,
'data' => [
[
//'id' => 3,
//'key' => 1,
'start' => '09:00:00',
'end' => '17:00:00'
]
],
'break_interval' => '',
'break_message' => '',
'welcome_message' => '',
'ns_welcome_message' => '',
'closed_message' => '',
'closed_gosub' => ''
]
]
]
];
Example hash generation:
$params['api_hash'] = md5(json_encode($params) . 'your_api_key'); // make hash
Example of sending data:
$url = 'https://[YOUR-PBX-URL]/api/schedule';
$token = 'your_api_token';
echo curlPost($url, json_encode($params), array("Authorization: Bearer {$token}", "Content-Type: application/json"));
Data sent JSON¶
{
"action": "save",
"data": {
"element_type": "project",
"schedule_type": "weekdays",
"schedule_data": [
{
"element_id": 1,
"day": 1,
"data": [
{
"start": "09:00:00",
"end": "18:00:00"
}
],
"break_interval": "",
"break_message": "",
"welcome_message": "",
"ns_welcome_message": "",
"closed_message": "",
"closed_gosub": ""
},
{
"element_id": 1,
"day": 2,
"data": [
{
"start": "09:00:00",
"end": "17:00:00"
}
],
"break_interval": "",
"break_message": "",
"welcome_message": "",
"ns_welcome_message": "",
"closed_message": "",
"closed_gosub": ""
}
]
},
"api_hash": "07112231a9c89f5b108af08608a97b07"
}
Response¶
In case of success (saved = the number of intervals added, modified or deleted):
{
"has_error": false,
"messages": [],
"results": {
"saved": 1
}
}
Or in case of error:
{
"has_error": true,
"messages": [
"Errors saving schedule: Invalid schedule Element ID for Monday; Invalid Start time for Tuesday (#1)"
],
"results": [ ]
}
Available in other languages: RO