Project

General

Profile

API - Channel

API Channel is used to manipulate the active calls (channels) on the PBX. The action parameter is required: list, hangup, originate or redirect. For hangup, originate and redirect the parameters are sent in the data array. The response does not contain pagination.

The data is transmitted by POST or GET

API URL

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

List - show all channels
Array
(
    [action] => list
    [api_hash] => 0f25e797e72d0dbba96d2c571a7bd6ba
)

Response: results.raw contains the channels as returned by Asterisk (the key is the channel name), and results.formatted the processed calls (direction, queue, agent, duration).

{
    "has_error": false,
    "messages": [ ],
    "results": {
        "raw": {
            "PJSIP/john-doe-00000027": {
                "Channel": "PJSIP/john-doe-00000027",
                "Context": "internal",
                "Exten": "s",
                "Priority": "1",
                "Stats": "Up",
                "Application": "AppQueue",
                "Data": "(Outgoing Line)",
                "CallerID": "0712345678",
                "Accountcode": "",
                "PeerAccount": "inbound",
                "Amaflags": "3",
                "Duration": "42",
                "Bridged": "1730800000.120",
                "UniqueID": "1730800000.121" 
            }
        },
        "formatted": [
            {
                "uniqueid": "1730800000.120",
                "channel": "PJSIP/default-trunk-00000026",
                "caller_id": "0712345678",
                "parsed_user": "john-doe",
                "direction": "in",
                "info": "Queue",
                "info_key": "test-queue",
                "queue_name": "test-queue",
                "duration": "42",
                "status": "speaking",
                "call_time": "00:00:42",
                "connected_line": "John Doe" 
            }
        ]
    }
}

Hangup - hang up the specified channel

The channel parameter is required and must be a valid channel name (e.g. PJSIP/john-doe-00000027, from list).

Array
(
    [action] => hangup
    [data] => Array
        (
            [channel] => SIP/john-doe-00000027
        )

    [api_hash] => 0f25e797e72d0dbba96d2c571a7bd6ba
)

Originate - create a new channel and connect it to a dialplan extension

All parameters are required: tech (the called channel, e.g. PJSIP/john-doe or Local/10@internal), exten (letters, digits and * # + - ) and context (letters, digits, - and _). When the channel answers, it is sent to the _exten extension in the context context. The call is originated asynchronously: the response only confirms that it was started. Originate to an application (appname / appdata) is not allowed.

Array
(
    [action] => originate
    [data] => Array
        (
            [tech] => PJSIP/john-doe
            [exten] => 10
            [context] => internal
        )

    [api_hash] => 0f25e797e72d0dbba96d2c571a7bd6ba
)

Response: Channel PJSIP/john-doe successfully originated. If the extension does not exist in the context, the error is Failed on channel PJSIP/john-doe: Response: Error Message: Extension does not exist.

Redirect - redirect an existing channel to a dialplan extension

All parameters are required: channel (a valid channel name), context and priority (letters, digits, - and _), exten (letters, digits and * # + - _).

Array
(
    [action] => redirect
    [data] => Array
        (
            [channel] => SIP/john-doe-00000027
            [context] => internal
            [exten] => 504
            [priority] => 1
        )

    [api_hash] => 0f25e797e72d0dbba96d2c571a7bd6ba
)

Hangup / redirect response

{
    "has_error": false,
    "messages": [ ],
    "results": [
        "Channel PJSIP/john-doe-00000027 successfully hung" 
    ]
}

Possible errors:

  • Request action is missing, Request data array is missing
  • Required parameter is missing from data array: channel (the key in messages is the parameter name)
  • Invalid channel, Invalid tech, Invalid context, Invalid exten, Invalid priority
  • Failed on channel ...: ... - the command could not be executed (e.g. the channel no longer exists)
  • Invalid action: ...
  • Manager error: ... - the PBX is not responding
{
    "has_error": true,
    "messages": {
        "channel": "Invalid channel" 
    },
    "results": [ ]
}

Available in other languages: RO