×

This API generates events based on the success or failure of the creation of the leg

POST

https://cpaas-api.in.exotel.com/v2/accounts/<your_sid>/legs

Parameter Name

Mandatory / Optional

Value

Description

contact_uri

Mandatory

String

Can use “sip:” or a indian phone number with 0 or with country prefix

network_type

Optional

String. {“pstn”, “voip”}. Default = “pstn”

Should be voip when “sip:” used in contact_uri, else “pstn”

exophone

Mandatory

String

Can use “sip:” or a indian phone number with 0 or with country prefix

custom_param

Optional

String

User specified custom parameter. Will be sent back with external events

leg_event_endpoint

Mandatory

String


grpc endpoint to provide events to.

time_limit

Optional

Integer (in seconds).

 Default = 4 hours

Total time for leg

timeout

Optional

Integer (in seconds).

 Default = 30 seconds

Timeout for creating a leg. Time from which the leg is initiated to when the leg is picked up

setup_timeout

Optional

Integer (in seconds).

 Default = 30 seconds

The time period from channel initialization till the Channel starts Ringing. Setup Timeout is the max allowed Setup Time

ring_timeout

Optional

Integer (in seconds).

 Default = 30 seconds

The time period from when the channel starts ringing till it is answered.

requested_dc_code

Optional

String

If provided the leg would be created from the given DC Code

requested_nso_code

Optional

String

If provided the leg would be created from the given NSO Code

reference_leg_sid

Optional

String

If provided the leg would be created from the same location as the reference leg sid.

Note: If two or more legs are being bridged, they should be co-located. This can be achieved by passing the reference_leg_sid parameter while creating subsequent legs which are to be bridged with the first leg

amd_enable

Optional

Bool (default : false)

If set to true,it will detect whether the call is answered by a machine.

async_amd

Optional

Bool (default : false)

Applicable only when 

amd_enable is true.

If async_amd is set to false, it will send
answered_by field in leg_answered event.

If async_amd is set to true ,it will send answered_by  in a separate external event : amd_result_success on successful amd detection.

priority

Optional

String (default: normal)

Applicable only when CPS (calls per second) throughput control is enabled for account and telco pair

CPS throughput control is not enabled by default

Allowed values are normal or high

If a call is enqueued as a result of this , then the response contains status as enqueued in the response

{
    “contact_uri”: “09163816621”,
    “exophone”: “08030752400”,
    “leg_event_endpoint”: “grpc://127.0.0.1:9001”,
    “network_type” : “pstn”,
    “timeout”: 200,
    “time_limit”: 200
}

 

Parameter Name

Type & Value

leg_sid

string

created_at

string

account_sid

string

contact_uri

string

network_type

string

exophone

string

custom_param

string / null

leg_event_endpoint

string

{
    “request_id”: “811b113c561a4d35bd8520112eb629f7”,
    “method”: “POST”,
    “http_code”: 202,
    “response”: {
        “error_data”: null,
        “data”: {
            “leg_sid”: “2QYATxQ9t4UKcUwcqJClSa9OEZ400000”,
            “created_at”: “2023-05-31 08:02:32.608752571 +0000 UTC”,
            “account_sid”: “exotel60”,
            “contact_uri”: “09163816621”,
            “network_type”: “pstn”,
            “exophone”: “08030752400”,
            “custom_param”: null,
            “leg_event_endpoint”: “127.0.0.1:9001”
        }
    }
}

External Events:

Key

Type

Sample Value

event_sid

string

2QmI6NeiCjDaz5egUwkVlJCOtUQ00000

event_type

string

leg_lifecycle_event

event_name

string

incoming_leg

event_timestamp

object

 

- seconds

integer

1685952153

- nanos

integer

285423183

event_data

object

 

- data

object

 

data

object

 

- account_sid

string

exotel60

- caller_id

string

8030752400

- contact_uri

string

7417712343

- date_created

string

2023-06-05T08:02:33.214702529Z

- date_updated

string

2023-06-05T08:02:33.214702529Z

- dc_code

string

101

- direction

string

inbound

- exophone

string

8030752400

- leg_sid

string

2QmI6PngBZ7gc3VXJnOzCVBLsNP00000

- network_type

string

pstn

- nso_code

string

a8140aaa-ce40-11ed-9a09-0242ac110003

- start_time

string

2023-06-05T08:02:33.214702529Z

- state

string

ringing

- time_limit

integer

14400

Events Create Leg can generate:

Event Name

EventType

event_data.data

event_data.error

data

“leg_connecting”

leg_lifecycle_event

None

-

"state": "connecting"

“leg_ringing”

leg_lifecycle_event

None

-

"state": "ringing"

“leg_answered”

leg_lifecycle_event

None

-

"state": "connected"


(if amd_enable is true )

"answered_by":"BEEP/ HUMAN / MACHINE"

“amd_result_success”

leg_action_event

None

 

(If amd_enable, async_amd both is set to  true )


"state": "connected",

"answered_by":"BEEP/ HUMAN / MACHINE"

“leg_terminated”

leg_lifecycle_event

"hangup_cause_code": 16,
"sip_cause_code": 487,
"sip_reason": "..."

“error_code”: ..,

“message”:”...”,

“description”:”...”

"state": "terminal", "terminal_status": "completed/ busy/ no-answer/ failed"

“leg_failed_to_create”

leg_lifecycle_event

None

“error_code”: ..,

“message”:”...”,

“description”:”...”

"state": "terminal", "terminal_status": "failed"

 

{
    “event_sid”: “2K8DQQuKWiXhXdfpMnXJYKVoTdB”,
    “event_type”: “leg_lifecycle_event”,
    “event_name”: “leg_incoming”,
    “event_timestamp”: {
        “seconds”: 1673347299,
        “nanos”: 607761576
    },
    “data”: {
        “account_sid”: “exotel60”,
        “caller_id”: “08030752400”,
        “contact_uri”: “09163816622”,
        “date_created”: “2023-01-10T10:41:39.607712401Z”,
        “date_updated”: “2023-01-10T10:41:39.607712401Z”,

         “dc_code”: “101”,
        “direction”: “inbound”,
        “exophone”: “08030752400”,
        “leg_sid”: “2K8DQQr2eoPW6HXJej7VesxsTUy00000”,
        “network_type”: “pstn”,

         “nso_code”: “9988fd96-ce41-11ed-9a09-0242ac110003”,
        “start_time”: “2023-01-10T10:41:39.03987348Z”,
        “state”: “ringing”,
        “time_limit”: 14400
    }
}

{
  “event_sid”: “2Qmm2gI1sRmNkiGNyREGKHv2PnG00000”,
  “event_type”: “leg_lifecycle_event”,
  “event_name”: “leg_connecting”,
  “event_timestamp”: {
    “seconds”: 1685966925,
    “nanos”: 743609442
  },
  “data”: {
    “account_sid”: “exotel60”,
    “caller_id”: “8030752501”,
    “contact_uri”: “07417712343”,
    “custom_param”: “MD_LEGS”,
    “date_created”: “2023-06-05T12:08:45.521094309Z”,
    “date_updated”: “2023-06-05T12:08:45.631124146Z”,
    “dc_code”: “101”,
    “direction”: “outbound”,
    “exophone”: “08030752400”,
    “leg_sid”: “2Qmm2j6Y9MfjJfQMNg61K8DaKxv00000”,
    “network_type”: “pstn”,
    “nso_code”: “9988fd96-ce41-11ed-9a09-0242ac110003”,
    “start_time”: “2023-06-05T12:08:45.630677211Z”,
    “state”: “connecting”,
    “time_limit”: 14400
  }
}