Create a Subaccount

Creates a new Subaccount object.

API Endpoint

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

Arguments

name required string

A human-readable name for the subaccount.

enabled boolean

Specify if the subaccount should be enabled. Takes a value of true or false. Defaults to false.

Response

HTTP Status Code: 201

{
	"api_id": "324a7dd8-0db2-11e4-8a4a-123140008edf",
	"auth_id": "SAXXXXXXXXXXXXXXXXXX",
	"auth_token": "MTZjYWM0YzVjNjMwZmVmODFiNWJjNPJmOGJjZjgw",
	"message": "created"
}

Example Request

1
2
3
4
5
6
7
import plivo

client = plivo.RestClient()
response = client.subaccounts.create(
    name='Wayne Enterprises Subaccount',
    enabled=True, )
print(response)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#
# Example for Subaccount Create
#
require 'rubygems'
require 'plivo'

include Plivo
include Plivo::Exceptions

api = RestClient.new("YOUR_AUTH_ID", "YOUR_AUTH_TOKEN")

begin
  response = api.subaccounts.create(
    'Test Subaccount',
    true,
  )
  puts response
rescue PlivoRESTError => e
  puts 'Exception: ' + e.message
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Example for Subaccount create

var plivo = require('plivo');

(function main() {
    'use strict';

    // As the auth_id and auth_token are unspecified, Plivo will fetch them from the PLIVO_AUTH_ID and PLIVO_AUTH_TOKEN environment variables.
    var client = new plivo.Client();
    client.subAccounts.create(
        "Test Subaccount", // name
        true                 // enabled
    ).then(function (response) {
        console.log(response);
    }, function (err) {
        console.error(err);
    });
})();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
/**
 * Example for Subaccount create
 */
require 'vendor/autoload.php';
use Plivo\RestClient;
use Plivo\Exceptions\PlivoRestException;
$client = new RestClient("YOUR_AUTH_ID", "YOUR_AUTH_TOKEN");

try {
    $response = $client->subaccounts->create(
        'Test Subaccount',
        True
    );
    print_r($response);
}
catch (PlivoRestException $ex) {
    print_r(ex);
}
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 com.plivo.api.samples.subaccount;

import java.io.IOException;
import com.plivo.api.Plivo;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.account.Subaccount;
import com.plivo.api.models.account.SubaccountCreateResponse;

/**
* Example for Subaccount create
*/
class SubaccountCreate {
    public static void main(String [] args) {
        Plivo.init();
        try {
            SubaccountCreateResponse response = Subaccount.creator("Test Subaccount")
                .enabled(true)
                .create();

            System.out.println(response);
        } catch (PlivoRestException | IOException e) {
            e.printStackTrace();
        }
    }
}
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
29
30
/**
 * Example for Subaccount Create
 */
using System;
using System.Collections.Generic;
using Plivo;
using Plivo.Exception;

namespace PlivoExamples
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var api = new PlivoApi("YOUR_AUTH_ID", "YOUR_AUTH_TOKEN");
            try
            {
                var response = api.Subaccount.Create(
                    enabled:true,
                    name:"Test Subaccount dotNet"
                );
                Console.WriteLine(response);
            }
            catch (PlivoRestException e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
        }
    }
}
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/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Example for Subaccount create
package main

import "fmt"
import "github.com/plivo/plivo-go"
 
func main() {
	client, err := plivo.NewClient("", "", &plivo.ClientOptions{})
	if err != nil {
		panic(err)
	}
	response, err := client.Subaccounts.Create(
		plivo.SubaccountCreateParams{
			Name: "Test Subaccount",
			Enabled: true,
		},
	)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Response: %#v\n", response)
}