# Asterisk Project : Asterisk 13 Channels REST API

Created and last modified by wikibot on Aug 11, 2014

# Channels

Method | Path | Return Model | Summary
--- | --- | --- | ---
GET | /channels | List[Channel] | List all active channels in Asterisk.
POST | /channels | Channel | Create a new channel (originate).
GET | /channels/{channelId} | Channel | Channel details.
POST | /channels/{channelId} | Channel | Create a new channel (originate with id).
DELETE | /channels/{channelId} | void | Delete (i.e. hangup) a channel.
POST | /channels/{channelId}/continue | void | Exit application; continue execution in the dialplan.
POST | /channels/{channelId}/answer | void | Answer a channel.
POST | /channels/{channelId}/ring | void | Indicate ringing to a channel.
DELETE | /channels/{channelId}/ring | void | Stop ringing indication on a channel if locally generated.
POST | /channels/{channelId}/dtmf | void | Send provided DTMF to a given channel.
POST | /channels/{channelId}/mute | void | Mute a channel.
DELETE | /channels/{channelId}/mute | void | Unmute a channel.
POST | /channels/{channelId}/hold | void | Hold a channel.
DELETE | /channels/{channelId}/hold | void | Remove a channel from hold.
POST | /channels/{channelId}/moh | void | Play music on hold to a channel.
DELETE | /channels/{channelId}/moh | void | Stop playing music on hold to a channel.
POST | /channels/{channelId}/silence | void | Play silence to a channel.
DELETE | /channels/{channelId}/silence | void | Stop playing silence to a channel.
POST | /channels/{channelId}/play | Playback | Start playback of media.
POST | /channels/{channelId}/play/{playbackId} | Playback | Start playback of media and specify the playbackId.
POST | /channels/{channelId}/record | LiveRecording | Start a recording.
GET | /channels/{channelId}/variable | Variable | Get the value of a channel variable or function.
POST | /channels/{channelId}/variable | void | Set the value of a channel variable or function.
POST | /channels/{channelId}/snoop | Channel | Start snooping.
POST | /channels/{channelId}/snoop/{snoopId} | Channel | Start snooping.

## GET /channels

List all active channels in Asterisk.

## POST /channels

Create a new channel (originate). The new channel is created immediately and a snapshot of it returned. If a Stasis application is provided it will be automatically subscribed to the originated channel for further events and updates.

### Query parameters

- endpoint: string - (required) Endpoint to call.
- extension: string - The extension to dial after the endpoint answers
- context: string - The context to dial after the endpoint answers. If omitted, uses 'default'
- priority: long - The priority to dial after the endpoint answers. If omitted, uses 1
- app: string - The application that is subscribed to the originated channel, and passed to the Stasis application.
- appArgs: string - The application arguments to pass to the Stasis application.
- callerId: string - CallerID to use when dialing the endpoint or extension.
- timeout: int = 30 - Timeout (in seconds) before giving up dialing, or -1 for no timeout.
- channelId: string - The unique id to assign the channel on creation.
- otherChannelId: string - The unique id to assign the second channel when using local channels.

### Body parameter

- variables: containers - The "variables" key in the body object holds variable key/value pairs to set on the channel on creation. Other keys in the body object are interpreted as query parameters. Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } }

### Error Responses

- 400 - Invalid parameters for originating a channel.

## GET /channels/{channelId}

Channel details.

### Path parameters

- channelId: string - Channel's id

### Error Responses

- 404 - Channel not found

## POST /channels/{channelId}

Create a new channel (originate with id). The new channel is created immediately and a snapshot of it returned. If a Stasis application is provided it will be automatically subscribed to the originated channel for further events and updates.

### Path parameters

- channelId: string - The unique id to assign the channel on creation.

### Query parameters

- endpoint: string - (required) Endpoint to call.
- extension: string - The extension to dial after the endpoint answers
- context: string - The context to dial after the endpoint answers. If omitted, uses 'default'
- priority: long - The priority to dial after the endpoint answers. If omitted, uses 1
- app: string - The application that is subscribed to the originated channel, and passed to the Stasis application.
- appArgs: string - The application arguments to pass to the Stasis application.
- callerId: string - CallerID to use when dialing the endpoint or extension.
- timeout: int = 30 - Timeout (in seconds) before giving up dialing, or -1 for no timeout.
- otherChannelId: string - The unique id to assign the second channel when using local channels.

### Body parameter

- variables: containers - The "variables" key in the body object holds variable key/value pairs to set on the channel on creation. Other keys in the body object are interpreted as query parameters. Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } }

### Error Responses

- 400 - Invalid parameters for originating a channel.

## DELETE /channels/{channelId}

Delete (i.e. hangup) a channel.

### Path parameters

- channelId: string - Channel's id

### Query parameters

- reason: string - Reason for hanging up the channel

### Error Responses

- 400 - Invalid reason for hangup provided
- 404 - Channel not found

## POST /channels/{channelId}/continue

Exit application; continue execution in the dialplan.

### Path parameters

- channelId: string - Channel's id

### Query parameters

- context: string - The context to continue to.
- extension: string - The extension to continue to.
- priority: int - The priority to continue to.

### Error Responses

- 404 - Channel not found
- 409 - Channel not in a Stasis application

## POST /channels/{channelId}/answer

Answer a channel.

### Path parameters

- channelId: string - Channel's id

### Error Responses

- 404 - Channel not found
- 409 - Channel not in a Stasis application

## POST /channels/{channelId}/ring

Indicate ringing to a channel.

### Path parameters

- channelId: string - Channel's id

### Error Responses

- 404 - Channel not found
- 409 - Channel not in a Stasis application

## DELETE /channels/{channelId}/ring

Stop ringing indication on a channel if locally generated.

### Path parameters

- channelId: string - Channel's id

### Error Responses

- 404 - Channel not found
- 409 - Channel not in a Stasis application

## POST /channels/{channelId}/dtmf

Send provided DTMF to a given channel.

### Path parameters

- channelId: string - Channel's id

### Query parameters

- dtmf: string - DTMF To send.
- before: int - Amount of time to wait before DTMF digits (specified in milliseconds) start.
- between: int = 100 - Amount of time in between DTMF digits (specified in milliseconds).
- duration: int = 100 - Length of each DTMF digit (specified in milliseconds).
- after: int - Amount of time to wait after DTMF digits (specified in milliseconds) end.

### Error Responses

- 400 - DTMF is required
- 404 - Channel not found
- 409 - Channel not in a Stasis application

## POST /channels/{channelId}/mute

Mute a channel.

### Path parameters

- channelId: string - Channel's id

### Query parameters

- direction: string = both - Direction in which to mute audio

### Error Responses

- 404 - Channel not found
- 409 - Channel not in a Stasis application

## DELETE /channels/{channelId}/mute

Unmute a channel.

### Path parameters

- channelId: string - Channel's id

### Query parameters

- direction: string = both - Direction in which to unmute audio

### Error Responses

- 404 - Channel not found
- 409 - Channel not in a Stasis application

## POST /channels/{channelId}/hold

Hold a channel.

### Path parameters

- channelId: string - Channel's id

### Error Responses

- 404 - Channel not found
- 409 - Channel not in a Stasis application

## DELETE /channels/{channelId}/hold

Remove a channel from hold.

### Path parameters

- channelId: string - Channel's id

### Error Responses

- 404 - Channel not found
- 409 - Channel not in a Stasis application

## POST /channels/{channelId}/moh

Play music on hold to a channel. Using media operations such as /play on a channel playing MOH in this manner will suspend MOH without resuming automatically. If continuing music on hold is desired, the stasis application must reinitiate music on hold.

### Path parameters

- channelId: string - Channel's id

### Query parameters

- mohClass: string - Music on hold class to use

### Error Responses

- 404 - Channel not found
- 409 - Channel not in a Stasis application

## DELETE /channels/{channelId}/moh

Stop playing music on hold to a channel.

### Path parameters

- channelId: string - Channel's id

### Error Responses

- 404 - Channel not found
- 409 - Channel not in a Stasis application

## POST /channels/{channelId}/silence

Play silence to a channel. Using media operations such as /play on a channel playing silence in this manner will suspend silence without resuming automatically.

### Path parameters

- channelId: string - Channel's id

### Error Responses

- 404 - Channel not found
- 409 - Channel not in a Stasis application

## DELETE /channels/{channelId}/silence

Stop playing silence to a channel.

### Path parameters

- channelId: string - Channel's id

### Error Responses

- 404 - Channel not found
- 409 - Channel not in a Stasis application

## POST /channels/{channelId}/play

Start playback of media. The media URI may be any of a number of URI's. Currently sound:, recording:, number:, digits:, characters:, and tone: URI's are supported. This operation creates a playback resource that can be used to control the playback of media (pause, rewind, fast forward, etc.)

### Path parameters

- channelId: string - Channel's id

### Query parameters

- media: string - (required) Media's URI to play.
- lang: string - For sounds, selects language for sound.
- offsetms: int - Number of media to skip before playing.
- skipms: int = 3000 - Number of milliseconds to skip for forward/reverse operations.
- playbackId: string - Playback ID.

### Error Responses

- 404 - Channel not found
- 409 - Channel not in a Stasis application

## POST /channels/{channelId}/play/{playbackId}

Start playback of media and specify the playbackId. The media URI may be any of a number of URI's. Currently sound: and recording: URI's are supported. This operation creates a playback resource that can be used to control the playback of media (pause, rewind, fast forward, etc.)

### Path parameters

- channelId: string - Channel's id
- playbackId: string - Playback ID.

### Query parameters

- media: string - (required) Media's URI to play.
- lang: string - For sounds, selects language for sound.
- offsetms: int - Number of media to skip before playing.
- skipms: int = 3000 - Number of milliseconds to skip for forward/reverse operations.

### Error Responses

- 404 - Channel not found
- 409 - Channel not in a Stasis application

## POST /channels/{channelId}/record

Start a recording. Record audio from a channel. Note that this will not capture audio sent to the channel. The bridge itself has a record feature if that's what you want.

### Path parameters

- channelId: string - Channel's id

### Query parameters

- name: string - (required) Recording's filename
- format: string - (required) Format to encode audio in
- maxDurationSeconds: int - Maximum duration of the recording, in seconds. 0 for no limit
- maxSilenceSeconds: int - Maximum duration of silence, in seconds. 0 for no limit
- ifExists: string = fail - Action to take if a recording with the same name already exists.
- beep: boolean - Play beep when recording begins
- terminateOn: string = none - DTMF input to terminate recording

### Error Responses

- 400 - Invalid parameters
- 404 - Channel not found
- 409 - Channel is not in a Stasis application; the channel is currently bridged with other hcannels; A recording with the same name already exists on the system and can not be overwritten because it is in progress or ifExists=fail
- 422 - The format specified is unknown on this system

## GET /channels/{channelId}/variable

Get the value of a channel variable or function.

### Path parameters

- channelId: string - Channel's id

### Query parameters

- variable: string - (required) The channel variable or function to get

### Error Responses

- 400 - Missing variable parameter.
- 404 - Channel not found
- 409 - Channel not in a Stasis application

## POST /channels/{channelId}/variable

Set the value of a channel variable or function.

### Path parameters

- channelId: string - Channel's id

### Query parameters

- variable: string - (required) The channel variable or function to set
- value: string - The value to set the variable to

### Error Responses

- 400 - Missing variable parameter.
- 404 - Channel not found
- 409 - Channel not in a Stasis application

## POST /channels/{channelId}/snoop

Start snooping. Snoop (spy/whisper) on a specific channel.

### Path parameters

- channelId: string - Channel's id

### Query parameters

- spy: string = none - Direction of audio to spy on
- whisper: string = none - Direction of audio to whisper into
- app: string - (required) Application the snooping channel is placed into
- appArgs: string - The application arguments to pass to the Stasis application
- snoopId: string - Unique ID to assign to snooping channel

### Error Responses

- 400 - Invalid parameters
- 404 - Channel not found

## POST /channels/{channelId}/snoop/{snoopId}

Start snooping. Snoop (spy/whisper) on a specific channel.

### Path parameters

- channelId: string - Channel's id
- snoopId: string - Unique ID to assign to snooping channel

### Query parameters

- spy: string = none - Direction of audio to spy on
- whisper: string = none - Direction of audio to whisper into
- app: string - (required) Application the snooping channel is placed into
- appArgs: string - The application arguments to pass to the Stasis application

### Error Responses

- 400 - Invalid parameters
- 404 - Channel not found