Create a Subaccount

POST Method

Kaleyra.io offers an API that enables you to create sub-account. You can configure the entities of the sub-account while creating them. Also, you have the option to change later the entities of the sub-account based on your business requirements.

Base URL

<https://api.kaleyra.io>

To create a sub-account, perform the following steps:

API request to create sub-account

To create a sub-account, use the /subaccounts endpoint with the following request method:

Request Format

curl --location --request POST '<url>/api/v1/<sid>/subaccounts' \
--header 'api-key: <api-key>' \
--header 'Content-Type: <content-type>' \
--data-raw '{
    "account_name" : "<account-name>",
    "email" : "<email-address>",
    "is_invited" : <is-invited>,
    "country_iso_code": "<country-iso-code>",
    "channels" :["<channels>"],
    "subaccount_credit_type" : "<subaccount-credit-type>"
}'

The following table describes the parameter used for creating sub-account:

ParameterData TypeDescriptionApplicableMandatoryExample
sidStringParent account SID (Security Identifier).Always applicable.YesHXXXXXXX071IN
content-typeStringThe format in which the data is sent.Always applicable.Yesapplication/json
api-keyStringParent account API key.Always applicable.YesAxxxxxxxxxxxxxxxxxxxxxxxxxxxx3
account_nameString - only alphanumeric, no special charactersSub-account name.Always applicable.YesJohn Doe
email_addressString - with valid emailSub-account user email address.Always applicable.Yes[[email protected]]
is_invitedBooleanIdentifier to send an invitation email to a sub-account user.
True - Invitation email will be sent to a sub-account user.
False - Invitation email will not be sent to a sub-account user.
Always applicable.YesTrue/False
country_iso_codeString - two-letter country ISO code.Country code for which you want to create Sub-account.Always applicable.YesIN
channelsStringChannels for which you want to give access to sub-account users. The supported channel is SMS.Always applicable.Yessms
subaccount_credit_typeStringAny one of the following Credit Types can be assigned to Subaccount:
Assigned - If you want to assign a specific credit amount to a sub-account.
Shared - If you want to share the usage with a sub-account.
Always applicable.Yesassigned
low_balance_alertBooleanIdentifier to send low balance alerts to specified email addresses.Applicable only when subaccount_credit_type = assigned.NoTrue/False
low_balance_limitNumberThe threshold amount to send alert email if sub-account’s balance goes below it.Applicable only when subaccount_credit_type = assigned and low_balance_alert is true.No500
low_balance_emailsArray of stringsThe email addresses to which low balance alert is sent. You can add more than one email address separated by a comma (,).Applicable only when subaccount_credit_type = assigned and low_balance_alert is true.No[[email protected]]
initial_credit_amountNumberInitial credit amount you want to assign to the sub-account user.Applicable only when subaccount_credit_type = assigned.No1000
monthly_limitNumberThe monthly limit you want to set for a sub-account user.Applicable only when a Monthly_limit is enabled for Parent account and when subaccount_credit_type = shared.No3000
ip_config_nameStringThe IP configuration created by Parent account. If passed in the request, by default it will be shared with sub-account and will be applied to the sub-account api_key as a whitelisted IP addresses/ranges.Applicable only if a parent is allowed to share ip_config.Notest1

Sample Request

The following is the sample request:

curl --location --request POST 'https://api.kaleyra.io/api/v1/HXXXXXXX071IN/subaccounts' \
--header 'api-key: Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3' \
--header 'Content-Type: application/json' \
--data-raw '{
    "account_name" : "John Doe",
    "email" : "[email protected]",
    "is_invited" : True,
    "country_iso_code": "IN",
    "channels" :["sms"],
    "subaccount_credit_type" : "Assigned"
}'

Sample Success Response

The following are the sample success response for different cases:

Case 1.: When subaccount_credit_type = assigned and low_balance_alert = false
{
    "code": "RBC103",
    "message": "Request executed successfully",
    "data": {
        "account_name": "John Doe",
        "email": "[email protected]",
        "status": "active",
        "sid": "HXXXXXXX071IN_1234",
        "api_key": "Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3",
        "channels": [
            "sms"
        ],
        "low_balance_alert": false,
        "subaccount_credit_type": "assigned",
        "balance": 1
    },
    "error": {},
    "status": 201
}
Case 2.: When subaccount__credit_type = assigned and low_balance_alert = true
{
    "code": "RBC103",
    "message": "Request executed successfully",
    "data": {
        "account_name": "John Doe",
        "email": "[email protected]",
        "status": "active",
        "sid": "HXXXXXXX071IN_1234",
        "api_key": "Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3",
        "channels": [
            "sms"
        ],
      	"low_balance_alert": "true",  
      	"low_balance_limit": "1",
        "low_balance_emails": "[email protected]",        
        "subaccount_credit_type": "assigned",
        "balance": 1
    },
    "error": {},
    "status": 201
}
Case 3.: When subaccount__credit_type = shared without monthly_limit
{
    "code": "RBC103",
    "message": "Request executed successfully",
    "data": {
        "account_name": "John Doe",
        "email": "[email protected]",
        "status": "active",
        "sid": "HXXXXXXX071IN_1234",
        "api_key": "Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3",
        "channels": [
            "sms"
        ],
        "subaccount_credit_type": "shared"       
    },
    "error": {},
    "status": 201
}
Case 4.: When subaccount__credit_type = shared with monthly_limit
{
    "code": "RBC103",
    "message": "Request executed successfully",
    "data": {        
        "account_name": "John Doe",
        "email": "[email protected]",
        "status": "active",
        "sid": "HXXXXXXX071IN_1234",
        "api_key": "Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3"
        "channels": [
            "sms"
        ],
        "subaccount_credit_type": "shared"
        "monthly_limit": 5
    },
    "error": {},
    "status": 201
}

Sample Failure Response

The following is a sample failure response:

{
    "code": "RBC2320",
    "message": "Error Occured in Rbac Register Wrapper API",
    "data": {},
    "error": {
        "Subaccount": "Subaccount with the same name already exists"
    },
    "status": 400
}

For more information about response codes and statuses for creating sub-account, see Response Codes and Statuses for Creating Subaccounts.