Transfer a call

A code snippet that shows how to transfer control of the current call to control by a new NCCO.

Example

Replace the following variables in the example code:

KeyDescription
VOICE_CALL_ID

The UUID of the call leg.

VOICE_NCCO_URL

The URL of the NCCO to execute. URLs must be array type.

Prerequisites

Execute the following command at your terminal prompt to create the JWT for authentication:

export JWT=$(nexmo jwt:generate $PATH_TO_PRIVATE_KEY application_id=$NEXMO_APPLICATION_ID)

Write the code

Add the following to transfer-a-call.sh:

curl -X PUT https://api.nexmo.com/v1/calls/$VOICE_CALL_ID \
  -H "Authorization: Bearer $JWT" \
  -H "Content-Type: application/json"\
  -d '{"action": "transfer",
      "destination": {"type": "ncco", "url": ["'"$VOICE_NCCO_URL"'"]}}'

View full source

Run your code

Save this file to your machine and run it:

bash transfer-a-call.sh

Try it out

You will need to:

  1. Set up a call and obtain the call UUID. You could use the 'connect an inbound call' code snippet to do this.
  2. Run the example code to transfer the call.
  3. Control will be transferred to a new NCCO, and you will hear a text-to-speech message to confirm this.

Further Reading

  • Conference Calling - This guide explains the two concepts Vonage associates with a call, a leg and a conversation.