Account API

The Account API lets you perform actions on your Plivo account. When you sign up on Plivo, you will be given your own account. You can retrieve your account details like email, available cash credits, name and time zone using the Account API. You can also modify your city and address to reflect in your invoices using the Account modify API.

The following actions can be performed with the Account API

BaseURI: https://api.plivo.com/v1/Account/

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. A phone number is required to receive calls. You can buy a Plivo phone number in over 20+ countries through the Buy Numbers tab on your Plivo account UI. Check the Voice API coverage page for all the supported countries.
  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.

Get Account Details

You can call this API to retrieve details like email address, cash credits, postal address, auto recharge settings, etc which is associated with your Plivo account. Returns an object representing your Plivo account.

GET https://api.plivo.com/v1/Account/{auth_id}/

Code

1
2
3
4
5
6
7
8
9
import plivo

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

# Get account details
response = p.get_account()
print str(response)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
require 'rubygems'
require 'plivo'
include Plivo

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

# Get account details
response = p.get_account()
print response
1
2
3
4
5
6
7
8
9
var plivo = require('plivo');
var p = plivo.RestAPI({
  authId: 'Your AUTH_ID',
  authToken: 'Your AUTH_TOKEN'
});

// Get account details
var response = p.get_account();
console.log(response);
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?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);

    // Get account details
    $response = $p->get_account();
    print_r ($response['response']);
?>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
package plivoexample;

import java.util.LinkedHashMap;
import com.plivo.helper.api.client.*;
import com.plivo.helper.api.response.account.Account;
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");

        // Get Details of account
        try {
            Account resp = api.getAccount();
            System.out.print(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
using System;
using System.Collections.Generic;
using RestSharp;
using Plivo.API;

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

            IRestResponse<Account> res = plivo.get_account();

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

Sample Response

(200,
  {
    "account_type": "standard",
    "address": "123 Main St.",
    "api_id": "0760deee-8a6e-11e4-a2d1-22000ac5040c",
    "auth_id": "XXXXXXXXXXXXXXXXXXXX",
    "auto_recharge": false,
    "billing_mode": "prepaid",
    "cash_credits": "188.18557",
    "city": "San Francisco",
    "name": "John Smith",
    "resource_uri": "/v1/Account/XXXXXXXXXXXXXXXXXXXX/",
    "state": "California",
    "timezone": "America/Los_Angeles"
  }
)

Modify an Account

If you would like to modify your account details, you could do so with this API. You can make changes to the name, city and the address fields.

POST https://api.plivo.com/v1/Account/{auth_id}/

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import plivo

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

# Modify account
params = {
  'name': 'John Smith', # Name of the account holder or business.
  'city': 'San Francisco', # City of the account holder
  'address': '123 Main St', # Address of the account holder
  'timezone': 'America/Los_Angeles' # Time zone of the account holder
}

response = p.modify_account(params)
print str(response)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
require 'rubygems'
require 'plivo'
include Plivo

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

# Modify account
params = {
  'name' => 'John Smith', # Name of the account holder or business.
  'city' => 'San Francisco', # City of the account holder
  'address' => '123 Main St', # Address of the account holder
  'timezone' => 'America/Los_Angeles' # Time zone of the account holder
}

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

// Modify account
var params = {
  'name': 'John Smith', // Name of the account holder or business.
  'city': 'San Francisco', // City of the account holder
  'address': '123 Main St', // Address of the account holder
  'timezone': 'America/Los_Angeles' // Time zone of the account holder
};

var response = p.modify_account(params);
console.log(response);
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<?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);

     // Modify account
    $params = array(
        'name' => 'John Smith', # Name of the account holder or business.
        'city' => 'San Francisco', # City of the account holder
        'address' => '123 Main St', # Address of the account holder
        'timezone' => 'America/Los_Angeles' # Time zone of the account holder
    );

    $response = $p->modify_account($params);
    print_r ($response['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
25
26
27
28
package plivoexample;

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");

        // Modify account
        LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
        params.put("name","John Smith"); // Name of the account holder or business
        params.put("city","San Francisco"); // City of the account holder
        params.put("address","123 Main St"); // Address of the account holder
        params.put("timezone","America/Los_Angeles"); // Account holder time zone

        try {
            GenericResponse resp = api.editAccount(params);
            System.out.print(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
25
26
using System;
using System.Collections.Generic;
using RestSharp;
using Plivo.API;

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

            IRestResponse<GenericResponse> res = plivo.modify_account(new Dictionary<string, string>()
            {
                {"name", "John Smith"}, // Name of the account holder or business.
                {"city", "San Francisco"}, // City of the account holder
                {"address", "123 Main St"}, // Address of the account holder
                {"timezone", "America/Los_Angeles"} // Time zone of the account holder
            });

            // Prints the response
            Console.Write(res.Content);
        }
    }
}
1
2
3
4
5
6
7
curl -i --user AUTH_ID:AUTH_TOKEN \
    -H "Content-Type: application/json" \
    -d '{"name": "John Smith",
         "city": "San Francisco",
         "address": "123 Main St",
         "timezone": "America/Los_Angeles"}' \
    https://api.plivo.com/v1/Account/{auth_id}/

Sample Response

(202,
  {
    "api_id": "2a9279e2-8267-11e5-a62c-22000afb0fc5",
    "message": "changed"
  }
)

Create a Subaccount

A subaccount is an account that is owned by a parent account. Using a subaccount makes it easier to segment, manage, and keep track of the account usages of each user independently.

POST https://api.plivo.com/v1/Account/{auth_id}/Subaccount/

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import plivo

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

# Create a sub account
params = {
  'name': 'test_subaccount1', # Name of the subaccount
  'enabled': 'True' # Specify if the subaccount should be enabled or not
}

response = p.create_subaccount(params)
print str(response)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
require 'rubygems'
require 'plivo'
include Plivo

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

# Create a sub account
params = {
    'name' => 'test_subaccount1', # Name of the subaccount
    'enabled' => 'True' # Specify if the subaccount should be enabled or not
}

response = p.create_subaccount(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'
});

// Modify account
var params = {
    'name': 'test_subaccount1', // Name of the subaccount
    'enabled': 'True' // Specify if the subaccount should be enabled or not
};

var response = p.create_subaccount(params);
console.log(response);
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<?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);

    // Create a sub account
    $params = array(
        'name' => 'test_subaccount1', # Name of the subaccount
        'eabled' => 'True' # Specify if the subaccount should be enabled or not
    );

    $response = $p->create_subaccount($params);
    print_r ($response['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
25
26
27
package plivoexample;

import java.util.LinkedHashMap;
import com.plivo.helper.api.client.*;
import com.plivo.helper.api.response.account.SubAccount;
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");

        // Create a sub account
        LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
        params.put("name","test_subaccount1"); // Name of the subaccount
        // Specify if the subaccount should be enabled or not
        params.put("enabled","True");

        try {
            SubAccount resp = api.createSubaccount(params);
            System.out.print(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 apps
{
    class Program
    {
        static void Main(string[] args)
        {
            RestAPI plivo = new RestAPI("Your AUTH_ID", "Your AUTH_TOKEN");

            IRestResponse<GenericResponse> res = plivo.create_subaccount(new Dictionary<string, string>()
            {
                {"name", "test_subaccount1"}, // Name of the subaccount
                {"enabled", "True"} // Specify if the subaccount should be enabled or not
            });

            //Prints the response
            Console.Write(res.Content);
        }
    }
}
1
2
3
4
curl -i --user AUTH_ID:AUTH_TOKEN \
    -H "Content-Type: application/json" \
    -d '{"name": "test_subaccount1","enabled": "True"}' \
    https://api.plivo.com/v1/Account/{auth_id}/Subaccount/

Sample Response

(201,
  {
    "api_id": "59d7a8fd-8266-11e5-a62c-22000afb0fc5",
    "auth_id": "XXXXXXXXXXXXXXXXX",
    "auth_token": "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
    "message": "created"
  }
)

Modify a Subaccount

If you would like to modify your subaccount, you could do so with this API. You can make changes to the name of the subaccount and specify whether to enable or disable it.

POST https://api.plivo.com/v1/Account/{auth_id}/Subaccount/{subauth_id}/

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import plivo

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

params = {
    # Auth ID of the subacccount to be modified
    'subauth_id': 'XXXXXXXXXXXXXXXXXXXX',
    'name': 'ABC_test' # Name of the subaccount
}

response = p.modify_subaccount(params)
print str(response)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
require 'rubygems'
require 'plivo'
include Plivo

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

params = {
    # Auth ID of the subacccount to be modified
    'subauth_id' => 'XXXXXXXXXXXXXXXXXXXX',
    'name' => 'ABC_test' # Name of the subaccount
}

response = p.modify_subaccount(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'
});

var params = {
    // Auth ID of the subacccount to to be modified
    'subauth_id': 'XXXXXXXXXXXXXXXXXXXX',
    'name': 'ABC_test' // Name of the subaccount
};

var response = p.modify_subaccount(params);
console.log(response);
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<?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 = array(
        # Auth ID of the subacccount to to be modified
        'subauth_id' => 'XXXXXXXXXXXXXXXXXXXX',
        'name' => 'ABC_test' # Name of the subaccount
    );

    $response = $p->modify_subaccount($params);
    print_r ($response['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
25
26
package plivoexample;

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> params = new LinkedHashMap<String, String>();
        // Auth ID of the subacccount to be modified
        params.put("subauth_id","XXXXXXXXXXXXXXXXXXXX");
        params.put("name","ABC_test"); // Name of the subaccount

        try {
            GenericResponse resp = api.editSubaccount(params);
            System.out.print(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
25
using System;
using System.Collections.Generic;
using RestSharp;
using Plivo.API;

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

            IRestResponse<GenericResponse> res = plivo.modify_subaccount(new Dictionary<string, string>()
            {
                // Auth ID of the subacccount to be modified
                {"subauth_id", "XXXXXXXXXXXXXXXXXXXX"},
                {"name", "ABC_test"} // Name of the subaccount
            });

            //Prints the response
            Console.Write(res.Content);
        }
    }
}
1
2
3
4
curl -i --user AUTH_ID:AUTH_TOKEN \
    -H "Content-Type: application/json" \
    -d '{"name": "ABC_test"}' \
    https://api.plivo.com/v1/Account/{auth_id}/Subaccount/{subauth_id}/

Sample Response

(202,
  {
    "api_id": "94a402fc-8a70-11e4-b423-22000ac8a2f8",
    "message": "changed"
  }
)

Get Details of a Single Subaccount

You can call this API to retrieve details of a subaccount like auth_id, auth_token, etc. Returns an object representing your Plivo subaccount.

GET https://api.plivo.com/v1/Account/{auth_id}/Subaccount/{subauth_id}/

Code

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

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

params = {
    # Subacccount Auth ID of which to retrieve details
    'subauth_id': 'XXXXXXXXXXXXXXXXXXXX'
}

response = p.get_subaccount(params)
print str(response)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
require 'rubygems'
require 'plivo'
include Plivo

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

params = {
    # Subacccount Auth ID of which to retrieve details
    'subauth_id' => 'XXXXXXXXXXXXXXXXXXXX'
}

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

var params = {
    // Subacccount Auth ID of which to retrieve details
    'subauth_id': 'XXXXXXXXXXXXXXXXXXXX'
};

var response = p.get_subaccount(params);
console.log(response);
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<?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 = array(
        // Subacccount Auth ID of which to retrieve details
        'subauth_id' => 'XXXXXXXXXXXXXXXXXXXX'
    );
    $response = $p->get_subaccount($params);
    print_r ($response['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
25
package plivoexample;

import java.util.LinkedHashMap;
import com.plivo.helper.api.client.*;
import com.plivo.helper.api.response.account.SubAccount;
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> params = new LinkedHashMap<String, String>();
        // Subacccount Auth ID of which to retrieve details
        params.put("subauth_id","XXXXXXXXXXXXXXXXXXXX");

        try {
            SubAccount resp = api.getSubaccount(params);
            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 apps
{
    class Program
    {
        static void Main(string[] args)
        {
            RestAPI plivo = new RestAPI("Your AUTH_ID", "Your AUTH_TOKEN");

            IRestResponse<SubAccount> res = plivo.get_subaccount(new Dictionary<string, string>()
            {
                // Subacccount Auth ID of which to retrieve details
                {"subauth_id", "XXXXXXXXXXXXXXXXXXXX"}
            });

            //Prints the response
            Console.Write(res.Content);
        }
    }
}
1
2
curl -i --user AUTH_ID:AUTH_TOKEN \
    https://api.plivo.com/v1/Account/{auth_id}/Subaccount/{subauth_id}/

Sample Response

(200,
  {
    "account": "/v1/Account/XXXXXXXXXXXXXXXXX/",
    "api_id": "f2ce3f25-8267-11e5-884b-22000afc235b",
    "auth_id": "ZZZZZZZZZZZZZZZZZZZZ",
    "auth_token": "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
    "created": "2015-11-03",
    "enabled": true,
    "modified": null,
    "name": "test_subaccount1",
    "new_auth_token": "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
    "resource_uri": "/v1/Account/XXXXXXXXXXXXXXXXX/Subaccount/ZZZZZZZZZZZZZZZZZZZZ/"
  }
)

Get Details of All Subaccounts

You can get details of all subaccounts associated with your main Plivo account. We return a list of all subaccounts.

GET https://api.plivo.com/v1/Account/{auth_id}/Subaccount/

Code

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

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

response = p.get_subaccounts()
# Print the entire response
print str(response)
# Print the total number of subaccounts
print "Total Subaccounts: %s" % (response[1]['meta']['total_count'])
 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)

response = p.get_subaccounts()
# Print the entire response
print response
# Print the total number of subaccounts
print "Total Subaccounts: " + response[1]['meta']['total_count']
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
var plivo = require('plivo');
var p = plivo.RestAPI({
  authId: 'Your AUTH_ID',
  authToken: 'Your AUTH_TOKEN'
});

var response = p.get_subaccounts();
// Print the entire response
console.log(response);
// Print the total number of subaccounts
console.log("Total Subaccounts: " + response[1]['meta']['total_count']);
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<?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);

    $response = $p->get_subaccounts();
    // Print the entire response
    print_r($response['response']);
    // Print the total number of subaccounts
    echo "<br>Total Subaccounts: " . $response['response']['meta']['total_count'];
?>
 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 plivoexample;

import java.util.LinkedHashMap;
import com.plivo.helper.api.client.*;
import com.plivo.helper.api.response.account.SubAccountFactory;
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");

        try {
            SubAccountFactory resp = api.getSubaccounts();
            // Print the entire response
            System.out.println(resp);
            //  Print the total number of subaccounts
            System.out.println("Total Subaccounts: " + resp.meta.totalCount);
        } 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
using System;
using System.Collections.Generic;
using RestSharp;
using Plivo.API;

namespace apps
{
    class Program
    {
        static void Main(string[] args)
        {
            RestAPI plivo = new RestAPI("Your AUTH_ID", "Your AUTH_TOKEN");
            IRestResponse<SubAccountList> res = plivo.get_subaccounts();
            // Print the entire response
            Console.Write(res.Content);
            // Print the total number of subaccounts
            Console.Write("Total Subaccounts: " + res.Data.meta.total_count);
        }
    }
}
1
2
curl -i --user AUTH_ID:AUTH_TOKEN \
    https://api.plivo.com/v1/Account/{auth_id}/Subaccount/

Sample Response

(200,
  {
    "api_id": "89354925-8268-11e5-a62c-22000afb0fc5",
    "meta": {
      "limit": 20,
      "next": null,
      "offset": 0,
      "previous": null,
      "total_count": 2
    },
    "objects": [
      {
        "account": "/v1/Account/XXXXXXXXXXXXXXXXXXX/",
        "auth_id": "ZZZZZZZZZZZZZZZZZZZZ",
        "auth_token": "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
        "created": "2015-11-03",
        "enabled": true,
        "modified": null,
        "name": "test_subaccount1",
        "new_auth_token": "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
        "resource_uri": "/v1/Account/XXXXXXXXXXXXXXXXXXX/Subaccount/ZZZZZZZZZZZZZZZZZZZ/"
      },
      {
        "account": "/v1/Account/AAAAAAAAAAAAAAAAAAA/",
        "auth_id": "BBBBBBBBBBBBBBBBBBBB",
        "auth_token": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
        "created": "2015-10-01",
        "enabled": true,
        "modified": null,
        "name": "testing",
        "new_auth_token": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
        "resource_uri": "/v1/Account/AAAAAAAAAAAAAAAAAAA/Subaccount/BBBBBBBBBBBBBBBBBBB/"
      }
    ]
  }
)

Delete a Subaccount

You can delete a subaccount with this API. This API would delete the subaccount and associate all Number, Endpoints and Applications (which are linked to the subaccount) to the main Plivo account.

DELETE https://api.plivo.com/v1/Account/{auth_id}/Subaccount/{subauth_id}/

Code

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

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

params = {
    # Auth ID of the subacccount to be deleted
    'subauth_id': 'XXXXXXXXXXXXXXXXXXXX'
}

response = p.delete_subaccount(params)
print str(response)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
require 'rubygems'
require 'plivo'
include Plivo

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

params = {
    # Auth ID of the subacccount to be deleted
    'subauth_id' => 'XXXXXXXXXXXXXXXXXXXX'
}

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

var params = {
  // Auth ID of the subacccount to be deleted
  'subauth_id': 'XXXXXXXXXXXXXXXXXXXX'
};

var response = p.delete_subaccount(params);
console.log(response);
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<?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 = array(
        # Auth ID of the subacccount to be deleted
        'subauth_id' => 'XXXXXXXXXXXXXXXXXXXX'
    );

    $response = $p->delete_subaccount($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
25
package plivoexample;

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> params = new LinkedHashMap<String, String>();
        // Auth ID of the subacccount to be deleted
        params.put("subauth_id","XXXXXXXXXXXXXXXXXXXX");

        try {
            GenericResponse resp = api.deleteSubaccount(params);
            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
using System;
using System.Collections.Generic;
using RestSharp;
using Plivo.API;

namespace apps
{
    class Program
    {
        static void Main(string[] args)
        {
            RestAPI plivo = new RestAPI("Your AUTH_ID", "Your AUTH_TOKEN");
            IRestResponse<GenericResponse> res = plivo.delete_subaccount(new Dictionary<string, string>()
            {
                // Auth ID of the subacccount to be deleted
                {"subauth_id", "XXXXXXXXXXXXXXXXXXXX"}
            });
            //Prints the response
            Console.Write(res.Content);
        }
    }
}
1
2
curl -X DELETE --user AUTH_ID:AUTH_TOKEN \
    https://api.plivo.com/v1/Account/{auth_id}/Subaccount/{subauth_id}/

Sample Response

Sample successful output
(204, '')

Sample unsuccessful output
(404,
  {
    "api_id": "5fbdd916-8f64-11e4-b153-22000abcaa64", 
    "error": "not found"
  }
)

Next Step

Learn how to manage Plivo Applications.

  1. Account API
  2. Application API
  3. Endpoint API
  4. Number API
  5. Phone Number API
  6. Pricing API
  7. API Pagination