REST API

Authorization in REST

If requests are made from localhost, then authorization is not required.
BASH
PHP
1
curl 'http://172.16.156.223/admin-cabinet/session/start' \
2
-X 'POST' --cookie-jar auth-cookies.txt \
3
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
4
-H 'X-Requested-With: XMLHttpRequest' \
5
--data 'login=admin&password=adminpassword'
Copied!
1
$host = '172.16.156.223';
2
$login = 'admin';
3
$password = 'admin';
4
5
$jar = new \GuzzleHttp\Cookie\CookieJar;
6
$client = new \GuzzleHttp\Client(['cookies' => $jar]);
7
$options = [
8
'headers' => [
9
"Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8",
10
"X-Requested-With" => "XMLHttpRequest"
11
],
12
'body' => http_build_query(['login' => $login,'password' => $password])
13
];
14
$resultHttp = $client->request('POST', "http://$host/admin-cabinet/session/start", $options);
15
$code = $resultHttp->getStatusCode();
16
if($code === 200) {
17
$content = $resultHttp->getBody()->getContents();
18
$authId = $jar->getCookieByName('PHPSESSID');
19
print_r($authId->getValue());
20
}
Copied!
Use $authId for other API requests.
JSON response:
1
{
2
"success": true,
3
"reload": "index/index",
4
"message": []
5
}
Copied!
In this example:
  • "172.16.156.223" - MikoPBX address
  • "admin" - Web interface user name
  • "adminpassword" - Web interface password
  • "auth-cookies.txt" - file for storing authorization data

Get peer statuses

BASH
PHP
1
curl -b auth-cookies.txt \
2
'http://172.16.156.223/pbxcore/api/sip/getPeersStatuses'
Copied!
1
$host = '172.16.156.223';
2
$authIdHP = 'SET AUTH ID';
3
$jar = \GuzzleHttp\Cookie\CookieJar::fromArray(
4
[
5
'PHPSESSID' => $authId
6
],
7
$host
8
);
9
10
$client = new \GuzzleHttp\Client(['cookies' => $jar]);
11
$resultHttp = $client->request('GET', "http://$host/pbxcore/api/sip/getPeersStatuses");
12
$code = $resultHttp->getStatusCode();
13
if($code === 200) {
14
$content = $resultHttp->getBody()->getContents();
15
print_r($content);
16
}
Copied!
JSON Response:
1
{
2
"jsonapi": {
3
"version": "1.0"
4
},
5
"result": true,
6
"data": [
7
{
8
"id": "201",
9
"state": "OK"
10
},
11
{
12
"id": "241",
13
"state": "UNKNOWN"
14
},
15
{
16
"id": "240",
17
"state": "UNKNOWN"
18
}
19
],
20
"messages": [],
21
"function": "getPeersStatuses",
22
"processor": "MikoPBX\\PBXCoreREST\\Lib\\SIPStackProcessor::getPeersStatuses",
23
"pid": 16729,
24
"meta": {
25
"timestamp": "2022-01-25T08:23:02-03:00",
26
"hash": "68fa513e851d9452aeed7f8f16ad61cb8705c4e5"
27
}
28
}
Copied!

Get peer status

BASH
PHP
1
curl -b auth-cookies.txt \
2
http://172.16.156.223/pbxcore/api/sip/getSipPeer \
3
--data '{"peer":"201"}'
Copied!
1
$host = '172.16.156.223';
2
$authId = 'SET AUTH ID';
3
$number = '203';
4
$jar = \GuzzleHttp\Cookie\CookieJar::fromArray(
5
[
6
'PHPSESSID' => $authId
7
],
8
$host
9
);
10
11
$options = [
12
'body' => json_encode(['peer' => $number])
13
];
14
$client = new \GuzzleHttp\Client(['cookies' => $jar]);
15
$resultHttp = $client->request('POST', "http://$host/pbxcore/api/sip/getSipPeer");
16
$code = $resultHttp->getStatusCode();
17
if($code === 200) {
18
$content = $resultHttp->getBody()->getContents();
19
print_r($content);
20
}
Copied!
JSON Response:
1
{
2
"jsonapi": {
3
"version": "1.son0"
4
},
5
"result": true,
6
"data": {
7
"Event": "ContactStatusDetail",
8
"ActionID": "PJSIPShowEndpoint_16729",
9
"AOR": "201",
10
"URI": "sip:[email protected]:60939;ob",
11
"UserAgent": "Telephone-PT1C 1.1",
12
"RegExpire": "1643110170",
13
"ViaAddress": "172.16.156.1:60939",
14
"CallID": "Z4Ys3hohywlIF6wn7K6I27EM0740nYVw",
15
"Status": "Reachable",
16
"RoundtripUsec": "5871",
17
"EndpointName": "201",
18
"ID": "201;@3002860e3ac957a2c2e13136226089d0",
19
"AuthenticateQualify": "0",
20
"OutboundProxy": "",
21
"Path": "",
22
"QualifyFrequency": "60",
23
"QualifyTimeout": "5.000",
24
"state": "OK"
25
},
26
"messages": [],
27
"function": "getSipPeer",
28
"processor": "MikoPBX\\PBXCoreREST\\Lib\\SIPStackProcessor::getPeerStatus",
29
"pid": 16729,
30
"meta": {
31
"timestamp": "2022-01-25T08:28:19-03:00",
32
"hash": "d31a2a7bce9864c4a85a774ddf22e7149196a531"
33
}
34
}
Copied!

Get provider statuses

SHELL
PHP
1
curl -b auth-cookies.txt \
2
'http://172.16.156.223/pbxcore/api/sip/getRegistry'
Copied!
1
$host = '172.16.156.223';
2
$authId = 'SET AUTH ID';
3
$jar = \GuzzleHttp\Cookie\CookieJar::fromArray(
4
[
5
'PHPSESSID' => $authId
6
],
7
$host
8
);
9
10
$client = new \GuzzleHttp\Client(['cookies' => $jar]);
11
$resultHttp = $client->request('GET', "http://$host/pbxcore/api/sip/getRegistry");
12
$code = $resultHttp->getStatusCode();
13
if($code === 200) {
14
$content = $resultHttp->getBody()->getContents();
15
print_r($content);
16
}
Copied!
JSON Response:
1
{
2
"jsonapi": {
3
"version": "1.0"
4
},
5
"result": true,
6
"data": [
7
{
8
"state": "OFF",
9
"id": "SIP-1601534775",
10
"username": "316811",
11
"host": "sip.zadarma.com"
12
},
13
{
14
"state": "OK",
15
"id": "SIP-1601534845",
16
"username": "316",
17
"host": "sip.zadarma.com"
18
}
19
],
20
"messages": [],
21
"function": "getRegistry",
22
"processor": "MikoPBX\\PBXCoreREST\\Lib\\SIPStackProcessor::getRegistry",
23
"pid": 16731,
24
"meta": {
25
"timestamp": "2022-01-25T08:31:18-03:00",
26
"hash": "a86bb88a16ff59a544f1d519a29a929dc42f6d4b"
27
}
28
}
Copied!
Last modified 5mo ago