Delete Exchange mailbox

Deletes an on-premises Exchange mailbox of a user.

DELETE ~/api/directoryObjects/exchange/mailbox?<parameters>

Query parameters

  • Name

  • Required

  • Type

  • Description

  • directoryobject

  • True

  • string

  • The identifier of the user whose mailbox to delete. A user can be identified by:

     Distinguished name (DN) {.black}
    # Example
    CN=John Smith,CN=Users,DC=example,DC=com
    
     Globally unique identifier (GUID) {.black}
    # Example
    7a4267ce-d354-44e7-8bd6-c681f1284a41
    
     Security identifier (SID) {.black}
    # Example
    S-1-5-21-3635565734-1729062999-1822655016-1627
    

Request headers

  • Name

  • Required

  • Description

  • Adm-Authorization

  • True

  • Specify the security token obtained during authentication.

Request body

Do not send a body with this request.

Responses

If successful, returns 200 OK status code and an operation result in the response body. Otherwise, returns one of the common HTTP error codes and an error description in the response body.

Examples

 Delete a mailbox

The following code sample deletes the Exchange mailbox of the specified user.

Request

PowerShell
Add-Type -AssemblyName System.Web
$baseUrl = "https://host.example.com/restApi"
$endpoint = "/api/directoryObjects/exchange/mailbox"

# Request parameters
$userIdentifier = [System.Web.HttpUtility]::UrlEncode("CN=John Smith,CN=Users,DC=example,DC=com")
$queryParams = "?directoryObject=$userIdentifier"
$requestUrl = $baseUrl + $endpoint + $queryParams
$requestHeaders = @{"Adm-Authorization" = YOUR-SECURITY-TOKEN}

# Make request
Invoke-RestMethod -Method DELETE -Headers $requestHeaders -Uri $requestUrl
C#
using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        const string baseUrl = "https://host.example.com";
        const string endpoint = "/restApi/api/directoryObjects/exchange/mailbox";

        // Request parameters
        const string userIdentifier = "CN=John Smith,CN=Users,DC=example,DC=com";
        UriBuilder requestUrl = new()
        {
            Host = baseUrl + endpoint,
            Query = $"?directoryObject={userIdentifier}"
        };

        // Initialize HTTP client
        using HttpClient client = new();
        client.DefaultRequestHeaders.Add("Adm-Authorization", YOUR-SECURITY-TOKEN);

        // Make request
        HttpResponseMessage response = await client.DeleteAsync(requestUrl.ToString());
        string responseBody = response.Content.ReadAsStringAsync().Result;
        Console.WriteLine(responseBody);
    }
}
cURL
curl --header 'Adm-Authorization: YOUR-SECURITY-TOKEN' \
--get -X DELETE 'https://host.example.com/restApi/api/directoryObjects/exchange/mailbox' \
--data-urlencode 'directoryObject=CN=John Smith,CN=Users,DC=example,DC=com'
node.js
var https = require('https');

// Request parameters
var userIdentifier = "CN=John Smith,CN=Users,DC=example,DC=com";
var requestPath = "/restApi/api/directoryObjects/exchange/mailbox"
    + `?directoryobject=${userIdentifier}`;

var options = {
    'method': 'DELETE',
    'hostname': 'host.example.com',
    'path': encodeURI(requestPath),
    'headers': {'Adm-Authorization': 'YOUR-SECURITY-TOKEN'}
};

// Make request
var req = https.request(options, res => {
    var data = [];

    res.on("data", chunk => {
        data.push(chunk);
    });

    res.on("end", () => {
        var body = Buffer.concat(data);
        console.log(body.toString());
    });

    res.on("error", error => {
        console.error(error);
    });
});
req.end();
Python
import requests
import json

baseUrl = "https://host.example.com/restApi"
endpoint = "/api/directoryObjects/exchange/mailbox"

# Request parameters
requestUrl = baseUrl + endpoint
requestHeaders = {"Adm-Authorization": YOUR-SECURITY-TOKEN}
queryParams = {"directoryobject": "CN=John Smith,CN=Users,DC=example,DC=com"}

# Make request
request = requests.delete(requestUrl, headers=requestHeaders, params=queryParams)
response = json.loads(request.content)
print(response)

Response

HTTP Status code: 200 OK
Response body:

{
    "resultType": 0,
    "innerMessages": [],
    "exception": null,
    "actualObjectDN": "CN=John Smith,CN=Users,DC=example,DC=com",
    "extraInfo": {}
}

See also