Update the Blocklist
The EasyLife 365 Mail API replaces the mail blocklist. The blocklist prevents end users from creating resources that match or contain blocklist terms. A term is either a specific email prefix or a simple wildcard term that uses an asterisk (*) for any characters. For instance, an organization might block prefixes such as admin@, marketing@ and sales@ to reduce unsolicited email.
Permissions
| Permission type | Permission | Rate limit |
|---|---|---|
| Delegated (work or school account) | Mail.Blocklist.Write | Create, update, delete |
| Application | Mail.Blocklist.ReadWrite.All or Mail.Manage.ReadWrite.All (either one) | Create, update, delete |
This route is part of the Admin API. Grant the application role on the EasyLife 365 Admin application in your tenant; see Call the API as an application. The delegated scope is https://api.easylife365.cloud/admin/Mail.Blocklist.Write. With the Insiders version, use api.insiders.easylife365.cloud.
HTTP request
PUT https://api.easylife365.cloud/admin/mail/v1/blocklist
Content-Type: application/json
HTTP request headers
| Header | Value |
|---|---|
| Authorization | Bearer token. (Required) |
| Content-Type | application/json |
Request body
The body is a JSON array of terms. The call replaces the whole blocklist, so send every term you want to keep.
| Rule | Detail |
|---|---|
| Terms | Strings. Each term is trimmed, and blank entries and duplicates are dropped. |
| Maximum | 100 terms. |
| Clear the list | Send an empty array []. |
[ "admin", "info", "marketing", "admin*", "*test*", "*user" ]
Response
200 OK with the array of terms that is now stored.
[ "admin", "info", "marketing", "admin*", "*test*", "*user" ]
Error responses
Errors are application/problem+json. See Call the API as an application.
| Status | Code | When |
|---|---|---|
| 400 | Mail.InvalidBlocklist | The body is missing, has more than 100 terms, or has only blank terms. Send [] to clear the list. |
| 401 | none | The token is missing or not valid. |
| 403 | none | The token has neither the scope nor one of the roles above, or it is a read role. |
| 429 | RateLimited | Too many calls. |
| 500 | InfrastructureError | The call could not be completed. Give support the requestId. |
{
"type": "https://docs.easylife365.cloud/errors/mail/invalid-blocklist",
"title": "The blocklist is not valid.",
"status": 400,
"code": "Mail.InvalidBlocklist",
"requestId": "e1d4b7a9-2c58-4f13-8a6e-7b0c9d3f5a21"
}
Audit
This call writes no entry to the audit log. The change is stored with the settings. With an application token the calling application is not recorded.
Example 1: Replace the blocklist with curl
curl -s -X PUT "https://api.easylife365.cloud/admin/mail/v1/blocklist" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '[ "admin", "info", "marketing", "admin*", "*test*", "*user" ]'
Example 2: Replace the blocklist as an application with PowerShell
First get a token with the scope https://api.easylife365.cloud/admin/.default. The token must carry one of the roles above.
$headers = @{ Authorization = "Bearer $token" }
$terms = @("admin", "info", "marketing", "admin*", "*test*", "*user")
$json = ConvertTo-Json -InputObject $terms -Compress
Write-Information "Setting the blocklist to: $json" -InformationAction Continue
Invoke-RestMethod -Method Put -Headers $headers -ContentType "application/json" -Body $json `
-Uri "https://api.easylife365.cloud/admin/mail/v1/blocklist"
Example 3: Replace the blocklist as a signed-in administrator with PowerShell
Register an application as described in Create Application Registration and note the tenant ID.
$tenantId = "<tenant-id>"
$scope = "https://api.easylife365.cloud/admin/Mail.Blocklist.Write"
az login --tenant $tenantId | Out-Null
$accessToken = az account get-access-token `
--tenant $tenantId `
--scope $scope `
--query accessToken `
--output tsv
$headers = @{ Authorization = "Bearer $accessToken" }
$json = ConvertTo-Json -InputObject @("admin", "info", "marketing") -Compress
Invoke-RestMethod -Method Put -Headers $headers -ContentType "application/json" -Body $json `
-Uri "https://api.easylife365.cloud/admin/mail/v1/blocklist"