How do I provision a mailbox via the API?

Andrew Porter
Published: 18 February 2020
Share:

What is the 20i Reseller Hosting API?

The 20i Reseller API gives you access to all the features and functionality of StackCP, allowing you to create a hosting control panel from scratch or integrate external services such as WHMCS.

This is for advanced web hosting resellers and the support we provide for the Reseller API is service-based only.

How to provision a mailbox via the API?

POST  /package/{id}/email/{id}

This endpoint permits the creation of mail objects, for example, mailboxes, and email forwarders.

The example below details an example payload for the creation of a mailbox.

PHP examples use our API wrapper, which can be downloaded here: https://my.20i.com/reseller/api

PHP

Request:

require_once "vendor/autoload.php";
$bearer_token = "INSERT API KEY"; //Your 20i API key.
$services_api = new \TwentyI\API\Services($bearer_token);
$packageId = "32025"; //The ID of the 20i package you wish to provision a mail object to.
$domain = "20isupport.com"; //The intended domain.
$prefix = "info"; //The prefix for the mailbox/mail object.
$password = "Password123"; //In this example, this is the password you wish to set for the mailbox.
$newMailbox = ["new" => ["mailbox" => ["local" => $prefix, "send" => "true", "receive" => "true", "password" => $password ] ] ];
$response = json_encode($services_api->postWithFields("/package/$packageId/email/$domain", $newMailbox), JSON_PRETTY_PRINT);
print_r($response);

Response:


{
    "result": {
        "result": [
            {
                "type": "mailbox",
                "id": "info",
                "generatedId": null,
                "password": "Password123"
            }
        ],
        "name": "20isupport.com"
    }
}

The response indicates that a mailbox object has been created with the details we specified in our payload. The mailbox can then be accessed as usual via the 20i control panel.