Project

General

Profile

API - Tools

API Tools is used for various actions in the PBX: restart, stopping some processes, running a task. The action parameter is required.

Data is transmitted via POST or GET

HTTP Headers:

Content-Type: application/json
Authorization: Bearer <token>

Example of hash generation and sending data:

$params['api_hash'] = md5(json_encode($params) . 'your_api_key'); // make hash

$url = 'https://[YOUR-PBX-URL]/api/tools';
$token = 'your_api_token';
echo curlPost($url, json_encode($params), array("Authorization: Bearer {$token}", "Content-Type: application/json"));

API URL

https://[YOUR-PBX-URL]/api/tools

Restart / Abort PBX

The action parameter can have the values:
  • restart_now: immediate restart, the calls in progress are closed
  • restart_gracefully: no longer accepts new calls and restarts after the calls in progress end
  • restart_when_convenient: restarts when there are no more calls in progress (new calls are still accepted)
  • abort_shutdown: cancels a scheduled restart

Response: Asterisk restart command executed successfully or the error Unable to execute Asterisk restart command / Manager error: ...

Array
(
    [action] => restart_now
    [api_hash] => 0f25e797e72d0dbba96d2c571a7bd6ba
)

Kill process

The action parameter must have the value kill, and process in data can be: push-server.php, events-watcher.php or events-watcher-push.php.

Response: Process successfully killed or one of the errors Invalid process, No matching process, Could not get process list, Could not kill process

Array
(
    [action] => kill
    [data] => Array
        (
            [process] => push-server.php
        )
    [api_hash] => 0f25e797e72d0dbba96d2c571a7bd6ba
)

Execute task

The action parameter must have the value execute_task, and task_id in data is the ID of the task (from Settings - Tasks). The task is run immediately, without changing its next scheduled run.

Response: Executed successfully! or one of the errors Invalid task (missing task_id), Invalid ID (task does not exist), Task already running, Task exec error: ...

Array
(
    [action] => execute_task
    [data] => Array
        (
            [task_id] => 1
        )
    [api_hash] => 0f25e797e72d0dbba96d2c571a7bd6ba
)

Response

In case of success:

{
    "has_error": false,
    "messages": [ ],
    "results": [
        "Executed successfully!" 
    ]
}

Or in case of error (Request action is missing, Invalid action: ... or the errors above):

{
    "has_error": true,
    "messages": [
        "Invalid process" 
    ],
    "results": [ ]
}

Available in other languages: RO