Hangup Calls Using API

Hanging up calls can be done easily through Plivo’s Hangup API. The following API enables you to hang up (i.e., cancel) a call initiated by the call API. If you are looking to hangup an incoming call without answering it, checkout the tutorial on how to reject a call using XML.

DELETE https://api.plivo.com/v1/Account/{auth_id}/Call/{call_uuid}/

Prerequisites

  1. Sign up for a free Plivo trial account.
  2. Check out our Helper Libraries page and install the right helper based on the programming language you want to use.
  3. Buy a Plivo phone number (optional).
  4. Use a web hosting service to host your web application. There are many inexpensive cloud hosting providers that you can use for just a few dollars a month. Follow the instructions of your hosting provider to host your web application.

Implementation

  1. Copy the relevant code below into a text file and save it. Lets call it Hangup.
    Note: Be sure to save it with the appropriate file extension for your language (i.e. .py for Python or .rb for Ruby, etc.)
  2. Replace Your AUTH_ID and Your AUTH_TOKEN with the AUTH ID and AUTH TOKEN found on your Plivo dashboard.
  3. Edit the call_uuid field with the ID of the call that has to be terminated. This ID will be sent to the answer URL once the call is connected.

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import plivo, plivoxml

auth_id = "Your AUTH_ID"
auth_token = "Your AUTH_TOKEN"
p = plivo.RestAPI(auth_id, auth_token)

# params references the UUID of the call to be hung up
params = {'call_uuid': 'defb0706-86a6-11e4-b303-498d468c930b'}

# Hang up a call
response = p.hangup_call(params)
print str(response)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
require 'rubygems'
require 'plivo'
include Plivo

AUTH_ID = "Your AUTH_ID"
AUTH_TOKEN = "Your AUTH_TOKEN"
p = RestAPI.new(AUTH_ID, AUTH_TOKEN)

# params references the UUID of the call to be hung up
params = {'call_uuid': 'defb0706-86a6-11e4-b303-498d468c930b'}

response = p.hangup_call(params)
print response
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
var plivo = require('plivo');
var p = plivo.RestAPI({
  authId: 'Your AUTH_ID',
  authToken: 'Your AUTH_TOKEN'
});

// UUID of the call to be hung up
var params = {'call_uuid': 'defb0706-86a6-11e4-b303-498d468c930b'};

// Prints the complete response
p.hangup_call(params, function (status, response) {
    console.log('Status: ', status);
    console.log('API Response:\n', response);
});
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<?php
    require 'vendor/autoload.php';
    use Plivo\RestAPI;
    $auth_id = "Your AUTH_ID";
    $auth_token = "Your AUTH_TOKEN";
    $p = new RestAPI($auth_id, $auth_token);

    # params references the UUID of the call to be hung up
    $params = array('call_uuid' => 'defb0706-86a6-11e4-b303-498d468c930b');

    $response = $p->hangup_call($params);
    print_r ($response)
?>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.plivo.test;
import java.util.LinkedHashMap;
import com.plivo.helper.api.client.*;
import com.plivo.helper.api.response.response.GenericResponse;
import com.plivo.helper.exception.PlivoException;

public class App {
    public static void main(String[] args) throws IllegalAccessException {
        String auth_id = "Your AUTH_ID";
        String auth_token = "Your AUTH_TOKEN";
        RestAPI api = new RestAPI(auth_id, auth_token, "v1");

        LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>();
        // parameters references the UUID of the call to be hung up
        parameters.put("call_uuid","defb0706-86a6-11e4-b303-498d468c930b");

        try {
            GenericResponse resp = api.hangupCall(parameters);
            System.out.println(resp);
        } catch (PlivoException e) {
            System.out.println(e.getLocalizedMessage());
        }
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
using System.Collections.Generic;
using RestSharp;
using Plivo.API;

namespace hangup
{
    class Program
    {
        static void Main(string[] args)
        {
            RestAPI plivo = new RestAPI("Your AUTH_ID", "Your AUTH_TOKEN");

            IRestResponse<GenericResponse> resp = plivo.hangup_call(new Dictionary<string, string>()
            {  // this references the UUID of the call to be hung up
                { "call_uuid", "defb0706-86a6-11e4-b303-498d468c930b" }
            });

            //Prints the response
            Console.Write(resp.Content);
            Console.ReadLine();
        }
    }
}
1
2
curl -i --user AUTH_ID:AUTH_TOKEN -X DELETE \
    https://api.plivo.com/v1/Account/{auth_id}/Call/{call_uuid}/

Sample Response

Successful Output
(204,"")

Unsuccessful Output
(404,
    {
        "api_id": "be4512a4-b5cc-11e4-9107-22000afaaa90",
        "error": "not found"
    }
)

Next Step

Learn how to receive an incoming call.

  1. Make an Outbound Call
  2. Play a Text-to-speech Message
  3. Connect Call to a Second Person
  4. Greet Caller by Name
  5. Play MP3/WAV Audio to Caller
  6. Hangup Using API
  7. Receive Incoming Call
  8. Forward Incoming Call
  9. Record Using API
  10. Screen Incoming Call
  11. Reject incoming call
  12. Get Details of all Calls
  13. Get Details of a single Call
  14. Get Details of Live Calls
  15. Build an IVR Phone Menu
  16. Conference Call
  17. Call Forward
  18. SIP Endpoint (Direct-Dial)
  19. Inbound Trunk
  20. Outbound Trunk