Legs API
Create a Leg
Leg Actions
42 min
description leg actions allow you to control an existing leg after it has been created using these actions, you can answer, hang up, play audio, record, gather dtmf, stream audio, bridge calls, and more all leg actions are executed via a single actions api using an exoml payload actions endpoint (common for all actions) endpoint post /v2/accounts/{account sid}/legs/{leg sid}/actions full url https //cpaas api in exotel com/v2/accounts/{account sid}/legs/{leg sid}/actions authentication type http basic authentication username api key password api token request headers content type application/json authorization basic \<base64(api key\ api token)> request body structure field type required description exoml string yes xml describing the action action custom param string no custom value echoed back in events 1\ answer answers an incoming leg exoml \<flow> \<answer /> \</flow> 2\ hangup terminates the leg exoml \<flow> \<hangup /> \</flow> 3\ play audio plays an audio file to the leg parameters attribute type default description loop integer 0 number of times to repeat (max 10) exoml \<flow> \<startplay loop="1"> https //example com/audio wav \</startplay> \</flow> 4\ stop play stops audio playback \<flow> \<stopplay /> \</flow> 5\ say (text to speech) converts text to speech and plays it on the leg parameters attribute description preferredttsengine polly or googletts language language code (default en) pollyvoiceid voice name (e g aditi) loop repeat count exoml \<flow> \<say preferredttsengine="polly" language="en" pollyvoiceid="aditi"> hello, welcome to exotel \</say> \</flow> 6\ stop say stops active tts playback \<flow> \<stopsay /> \</flow> 7\ start recording starts recording the leg parameters attribute description direction in, out, or both format wav or mp3 storagetype s3 or https exoml (s3) \<flow> \<startrecording direction="both" format="wav" storagetype="s3" /> \</flow> 8\ stop recording stops recording \<flow> \<stoprecording /> \</flow> 9\ gather (dtmf input) collects keypad input from the caller parameters attribute description numdigits number of digits to collect timeoutinsec timeout duration finishonkey key to terminate input exoml \<flow> \<gather numdigits="4" timeoutinsec="10" finishonkey="#"> \<say>enter your pin\</say> \</gather> \</flow> 10\ hold places the leg on hold exoml \<flow> \<hold /> \</flow> hold with music \<flow> \<hold> \<startplay>https //example com/moh wav\</startplay> \</hold> \</flow> 11\ unhold removes the leg from hold \<flow> \<unhold /> \</flow> 12\ mute mutes audio parameters attribute description direction in, out, or both \<flow> \<mute direction="out" /> \</flow> 13\ unmute unmutes audio \<flow> \<unmute direction="out" /> \</flow> 14\ join bridge joins the leg to an existing bridge parameters attribute description bridgesid bridge identifier absorbdtmf true / false \<flow> \<joinbridge bridgesid="bridge sid" absorbdtmf="true" /> \</flow> 15\ leave bridge removes the leg from a bridge \<flow> \<leavebridge /> \</flow> 16\ start streaming streams audio to/from a websocket endpoint parameters attribute description streamtype unidirectional or bidirectional streamurl websocket url exoml \<flow> \<startstream streamtype="bidirectional" streamurl="wss\ //bot example com/stream" /> \</flow> 17\ stop streaming stops active streaming \<flow> \<stopstream /> \</flow> 18\ monitor (listen / whisper) allows monitoring another leg parameters attribute description monitoringlegsid target leg rxaudio muted (listen) or enabled (whisper) \<flow> \<startmonitoring monitoringlegsid="leg sid" rxaudio="muted" /> \</flow> 19\ stop monitoring stops monitoring \<flow> \<stopmonitoring /> \</flow> 20\ refer (change event endpoint) updates the event delivery endpoint for the leg \<flow> \<refer legeventendpoint="grpc //new endpoint 9001" /> \</flow> common response http 202 – accepted { "request id" "abc123", "http code" 202, "response" { "data" { "leg sid" "leg sid" } } } error responses http code description 400 invalid exoml or parameters 401 authentication failed 403 not authorized 404 leg not found 429 rate limit exceeded 500 internal error best practices always check leg state before performing actions prefer events over polling for real time state use action custom param for correlation keep exoml small and single purpose per request
Have a question?
Our super-smart AI, knowledgeable support team and an awesome community will get you an answer in a flash.
To ask a question or participate in discussions, you'll need to authenticate first.
