Enkele eenvoudige voorbeelden met gebruikmaking van cURL (Windows Powershell gebruikers hebben wellicht de voorkeur voor Invoke-WebRequest dat een iets andere syntax gebruikt). U kunt ook Postman eens proberen, een app voor Windows, MaxOS en Linux die u in staat stelt om visueel requests te maken.
Omwille van correct versiebeheer, zijn de voorbeelden in het Engels.
Getting a user list using authentication via the query string and the default JSON output format
$ curl http://pbx.example.org/apis/pbx/users?key=8d0a0704a96db1773fcb52db2f3e0979
[{"username": "admin", "uuid": "828638d5-90c5-3abf-9609-7bb0c85ecd6d",
"full_name": null, "primary_phone": null}, {"username": "501",
"uuid": "26d6d6de-5050-3401-adfa-0967bb414213", "full_name": null,
"primary_phone": null}, {"username": "303", "uuid":
"c506e9b6-cdbf-360a-b022-b0ff2ad3b4de", "full_name": "John Brown",
"primary_phone": null}, {"username": "300", "uuid":
"092587dd-3b6f-3cfe-a769-654a0c1e5caa", "full_name": "phone 300",
"primary_phone": "92913299-f2d4-3a67-98ca-c76234d3d58f"},
{"username": "500", "uuid": "ad2852c1-5509-3068-b510-f98747b430a1",
"full_name": null, "primary_phone": null}, {"username": "301",
"uuid": "396edcb6-2818-3d7c-9056-029b972be3c4", "full_name": "phone 301",
"primary_phone": "9a899b91-3002-3565-9706-1bcff54589f4"},
{"username": "302", "uuid": "617e8555-b25a-35c2-b1c6-63cf8a867c0f",
"full_name": "John Black", "primary_phone": "97fb3488-e763-319d-9db3-f0345ae046ad"}]
Getting a user list using authentication via the query string and XML output format
$ curl http://pbx.example.org/apis/pbx/users.xml?key=8d0a0704a96db1773fcb52db2f3e0979
admin
828638d5-90c5-3abf-9609-7bb0c85ecd6d
501
26d6d6de-5050-3401-adfa-0967bb414213
John Brown
303
c506e9b6-cdbf-360a-b022-b0ff2ad3b4de
phone 300
92913299-f2d4-3a67-98ca-c76234d3d58f
300
092587dd-3b6f-3cfe-a769-654a0c1e5caa
500
ad2852c1-5509-3068-b510-f98747b430a1
phone 301
9a899b91-3002-3565-9706-1bcff54589f4
301
396edcb6-2818-3d7c-9056-029b972be3c4
John Black
97fb3488-e763-319d-9db3-f0345ae046ad
302
617e8555-b25a-35c2-b1c6-63cf8a867c0f
Using HTTP headers for authentication and output format selection
$ curl -u apiKey:8d0a0704a96db1773fcb52db2f3e0979 -H 'Accept: application/xml'
http://pbx.example.org/apis/pbx/users
admin
828638d5-90c5-3abf-9609-7bb0c85ecd6d
501
26d6d6de-5050-3401-adfa-0967bb414213
John Brown
303
c506e9b6-cdbf-360a-b022-b0ff2ad3b4de
phone 300
92913299-f2d4-3a67-98ca-c76234d3d58f
300
092587dd-3b6f-3cfe-a769-654a0c1e5caa
500
ad2852c1-5509-3068-b510-f98747b430a1
phone 301
9a899b91-3002-3565-9706-1bcff54589f4
301
396edcb6-2818-3d7c-9056-029b972be3c4
John Black
97fb3488-e763-319d-9db3-f0345ae046ad
302
617e8555-b25a-35c2-b1c6-63cf8a867c0f
Getting a user status
$ curl -u apiKey:8d0a0704a96db1773fcb52db2f3e0979 -H 'Accept: application/json'
http://pbx.example.org/apis/pbx/users/396edcb6-2818-3d7c-9056-029b972be3c4
{"username": "301", "dnd": false, "uuid": "396edcb6-2818-3d7c-9056-029b972be3c4",
"primary_phone": "9a899b91-3002-3565-9706-1bcff54589f4", "phone":
"9a899b91-3002-3565-9706-1bcff54589f4", "full_name": "phone 301",
"call_forward": null, "cw": false}
Getting a phone list
$ curl -u apiKey:8d0a0704a96db1773fcb52db2f3e0979 -H 'Accept: application/json'
http://pbx.example.org/apis/pbx/phones
[{"phone_username": "w7tny", "hot_desk": false, "type": "Snom 300 (V7 firmware)",
"uuid": "92913299-f2d4-3a67-98ca-c76234d3d58f", "name": "telefon 300"},
{"phone_username": "u215e", "hot_desk": true, "type": "Snom 300 (V8 firmware)",
"uuid": "9a899b91-3002-3565-9706-1bcff54589f4", "name": "telefon 301"}]
Getting a phone status
$ curl -u apiKey:8d0a0704a96db1773fcb52db2f3e0979 -H 'Accept: application/json'
http://pbx.example.org/apis/pbx/phones/9a899b91-3002-3565-9706-1bcff54589f4
{"status": "Idle", "uuid": "9a899b91-3002-3565-9706-1bcff54589f4", "type":
"Snom 300 (V8 firmware)", "status_code": 0, "phone_username": "u215e",
"hot_desk_user": "ad2852c1-5509-3068-b510-f98747b430a1", "hot_desk": true,
"name": "telefon 301"}
Fetching events (JSON)
$ curl -u apiKey:8d0a0704a96db1773fcb52db2f3e0979 -H 'Accept: application/json'
'http://pbx.example.org/apis/pbx/events?limit=10'
[{"status": "In Use", "event_type": "phone status update", "seq": 0,
"status_code": 1, "phone_uuid": "9a899b91-3002-3565-9706-1bcff54589f4",
"timestamp": "2012-03-22T13:48:52Z"}, {"status": "Ringing",
"event_type": "phone status update", "seq": 1, "status_code": 8,
"phone_uuid": "92913299-f2d4-3a67-98ca-c76234d3d58f", "timestamp": "2012-03-22T13:48:52Z"},
{"status": "In Use", "event_type": "phone status update", "seq": 2,
"status_code": 1, "phone_uuid": "92913299-f2d4-3a67-98ca-c76234d3d58f",
"timestamp": "2012-03-22T13:48:53Z"}, {"status": "Idle",
"event_type": "phone status update", "seq": 3, "status_code": 0,
"phone_uuid": "92913299-f2d4-3a67-98ca-c76234d3d58f", "timestamp": "2012-03-22T13:48:55Z"},
{"status": "Idle", "event_type": "phone status update", "seq": 4, "status_code": 0,
"phone_uuid": "9a899b91-3002-3565-9706-1bcff54589f4", "timestamp": "2012-03-22T13:48:56Z"}]
$ curl -u apiKey:8d0a0704a96db1773fcb52db2f3e0979 -H 'Accept: application/json'
'http://pbx.example.org/apis/pbx/events?limit=10&last=4'
[]
$ curl -u apiKey:8d0a0704a96db1773fcb52db2f3e0979 -H 'Accept: application/json'
'http://pbx.example.org/apis/pbx/events?limit=10&last=4'
[{"status": "In Use", "event_type": "phone status update", "seq": 5,
"status_code": 1, "phone_uuid": "9a899b91-3002-3565-9706-1bcff54589f4",
"timestamp": "2012-03-22T14:23:10Z"}, {"status": "Idle",
"event_type": "phone status update", "seq": 6, "status_code": 0,
"phone_uuid": "9a899b91-3002-3565-9706-1bcff54589f4", "timestamp": "2012-03-22T14:23:10Z"},
{"status": "In Use", "event_type": "phone status update", "seq": 7, "status_code": 1,
"phone_uuid": "9a899b91-3002-3565-9706-1bcff54589f4", "timestamp": "2012-03-22T14:23:16Z"},
{"phone_uuid": "9a899b91-3002-3565-9706-1bcff54589f4", "timestamp": "2012-03-22T14:23:19Z",
"user_uuid": "ad2852c1-5509-3068-b510-f98747b430a1", "event_type": "user logged out",
"seq": 8}, {"status": "Idle", "event_type": "phone status update", "seq": 9,
"status_code": 0, "phone_uuid": "9a899b91-3002-3565-9706-1bcff54589f4", "timestamp": "2012-03-22T14:23:19Z"}]
Fetching events (XML)
$ curl -u apiKey:8d0a0704a96db1773fcb52db2f3e0979 -H 'Accept: application/xml'
'http://pbx.example.org/apis/pbx/events?limit=3'
phone status update
9a899b91-3002-3565-9706-1bcff54589f4
7
In Use
1
2012-03-22T14:23:16Z
user logged out
9a899b91-3002-3565-9706-1bcff54589f4
8
2012-03-22T14:23:19Z
ad2852c1-5509-3068-b510-f98747b430a1
phone status update
9a899b91-3002-3565-9706-1bcff54589f4
9
Idle
0
2012-03-22T14:23:19Z
$ curl -u apiKey:8d0a0704a96db1773fcb52db2f3e0979 -H 'Accept: application/xml'
'http://pbx.example.org/apis/pbx/events?limit=3&last=9'
$ curl -u apiKey:8d0a0704a96db1773fcb52db2f3e0979 -H 'Accept: application/xml'
'http://pbx.example.org/apis/pbx/events?limit=3&last=9'
$ curl -u apiKey:8d0a0704a96db1773fcb52db2f3e0979 -H 'Accept: application/xml'
'http://pbx.example.org/apis/pbx/events?limit=3&last=9'
phone status update
9a899b91-3002-3565-9706-1bcff54589f4
10
In Use
1
2012-03-22T14:26:31Z
$ curl -u apiKey:8d0a0704a96db1773fcb52db2f3e0979 -H 'Accept: application/xml'
'http://pbx.example.org/apis/pbx/events?limit=3&last=10'
user logged in
9a899b91-3002-3565-9706-1bcff54589f4
11
2012-03-22T14:26:49Z
ad2852c1-5509-3068-b510-f98747b430a1
phone status update
9a899b91-3002-3565-9706-1bcff54589f4
12
Idle
0
2012-03-22T14:26:49Z
Fetching calls (JSON)
$curl -u apiKey:fb1c747701f2d21c35f4c7bc1f8ffebe -H 'accept: application/json'
'http://pbx.example.org/apis/pbx/acd/stats?calls=1'
{"queues": [{"service_level": 0.0, "calls_waiting": 1, "available_agents": 0,
"talk_time": 0, "longest_hold_time": 20, "service_level_interval": 0,
"name": "niekumam", "answered": 0, "all_agents": 4, "aborted": 2, "free_agents": 0,
"calls": [{"callerid_name": "FakeSip Linphone", "position": 1, "callerid_num": "123456",
"wait": 20}], "hold_time": 0, "logged_in_agents": 1,
"uuid": "ef382287-2c8c-32ca-a91f-b2216498fa17"}]}
Fetching calls (XML)
$curl -u apiKey:fb1c747701f2d21c35f4c7bc1f8ffebe -H 'accept: application/xml'
'http://pbx.example.org/apis/pbx/acd/stats.xml?calls=1'
1
11
0
0
0
2
0.0
4
1
0
0
FakeSip Linphone
123456
1
11
Fetching agents (JSON)
$curl -u apiKey:fb1c747701f2d21c35f4c7bc1f8ffebe -H 'accept: application/json'
'http://pbx.example.org/apis/pbx/acd/stats?agents=1' {"queues": [{"service_level": 0.0,
"calls_waiting": 0, "available_agents": 2, "talk_time": 0, "longest_hold_time": 0,
"service_level_interval": 0, "name": "niekumam", "answered": 0, "all_agents": 4, "aborted": 2, "free_agents": 2,
"agents": [{"status": "Unavailable", "paused": true, "last_call": "", "name": "304", "penalty": 1, "status_code": 5,
"user_uuid": "8ff48136-df77-388e-ab08-64268a221371", "calls_taken": 0}, {"status": "Unavailable", "paused": true,
"last_call": "", "name": "302", "penalty": 1, "status_code": 5, "user_uuid": "52b1e37c-9184-3e7a-b8b7-eb909bef0035",
"calls_taken": 0}, {"status": "Not In Use", "paused": false, "last_call": "", "name": "301", "penalty": 1,
"status_code": 1, "user_uuid": "cdad7e96-fa5f-3210-8641-20ed441d491b", "calls_taken": 0}, {"status": "Not In Use",
"paused": false, "last_call": "", "name": "300", "penalty": 1, "status_code": 1,
"user_uuid": "a8258b12-a203-3ccb-8365-95f40bdff152", "calls_taken": 0}], "hold_time": 0, "logged_in_agents": 2,
"uuid": "ef382287-2c8c-32ca-a91f-b2216498fa17"}]}
Fetching agents (XML)
$curl -u apiKey:fb1c747701f2d21c35f4c7bc1f8ffebe -H 'accept: application/xml'
'http://pbx.example.org/apis/pbx/acd/stats.xml?agents=1'
1
1
0
0
1
1
0.0
2
2
1
1
1
2013-12-19T11:59:15
301
False
1
Not In Use
1
cdad7e96-fa5f-3210-8641-20ed441d491b
0
300
False
1
Ringing
6
a8258b12-a203-3ccb-8365-95f40bdff152
Fetching call statistics for a specific queue (JSON)
$ curl -u apiKey:fb1c747701f2d21c35f4c7bc1f8ffebe -H 'accept: application/json' http://pbx.example.org/apis/pbx/acd/ef382287-2c8c-32ca-a91f-b2216498fa17/stats
{"service_level": 0.0, "calls_waiting": 1, "available_agents": 2, "talk_time": 0, "longest_hold_time": 72,
"service_level_interval": 0, "name": "niekumam", "answered": 0, "all_agents": 4, "aborted": 4, "free_agents": 2,
"hold_time": 0, "logged_in_agents": 2, "uuid": "ef382287-2c8c-32ca-a91f-b2216498fa17"}
Fetching call statistics for a specific queue (XML)
$ curl -u apiKey:fb1c747701f2d21c35f4c7bc1f8ffebe -H
'accept: application/xml'
http://pbx.example.org/apis/pbx/acd/ef382287-2c8c-32ca-a91f-b2216498fa17/stats
1
59
0
0
0
4
0.0
4
2
1
1