Skip to content

Get Leg

Retrieves a single call leg by legId. Use this to inspect one participant leg and its latest state.

Signature

// Callback version
fun getLeg(
  legId: String,
  callback: (Exception?, Leg?) -> Unit
)

// Suspend version
suspend fun getLeg(
  legId: String
): Leg

Parameters

ParameterTypeRequiredDescription
legIdstringYesIdentifier of the leg to retrieve

Return Type

Returns a Leg / VGVoiceLeg object for the requested leg.

Leg Properties

PropertyTypeDescription
id / legIdstringUnique leg identifier
typestringLeg type (e.g. app, phone, sip)
directionstringinbound or outbound
conversationIdstringConversation the leg belongs to
statusstringCurrent leg status
startTimestringLeg start timestamp
endTimestringLeg end timestamp
fromLegChannelOrigin channel — see below
toLegChannelDestination channel — see below
mediaStateMediaState?Optional: mute, earmuff, recording, and streaming state

LegChannel Properties

PropertyTypeDescription
typestring?Channel type (app, phone, sip, websocket)
userstring?User identifier — present for app-type channels
numberstring?Phone number — present for phone-type channels

Usage Example


 // Callback
 client.getLeg("legId") { err, leg ->
     err?.let {
         println("Error in getting leg: $it")
     }
     leg?.let {
         println("Leg id: ${it.id}, media state: ${it.mediaState}")
     }
 }

 // Coroutine
 try {
     val leg = client.getLeg("legId")
     println("Leg id: ${leg.id}, media state: ${leg.mediaState}")
 }
 catch(e: VGError) { /* Handle Vonage Error */ }
 catch(e: Error) { /* Handle generic Error */ }

Errors

Error TypeError CodeDescription
INTERNAL_ERRORvoice:error:no_call_found and relatedLeg cannot be found for provided legId
NETWORK_ERRORinternal:error:serviceNotAvailableNetwork/service failure while fetching leg
UNKNOWN_ERRORN/AUnexpected failure

For complete error reference and handling guidelines, see Error Reference.

Notes

  • Use getCallLegs when you need pagination over all legs in a call
  • legId values are available from call events like legStatusUpdate

Built with VitePress.