Call the API as an application
An application can call the EasyLife 365 Mail API without a signed-in user. It signs in with its own credential (the client credentials flow) and receives a token that carries an application role. This page shows how to get the token, how to grant the role, and which role each route accepts.
How the two kinds of call differ
| Signed-in administrator | Application | |
|---|---|---|
| Token carries | A delegated scope (scp claim) | An application role (roles claim), no scope |
| Rights | What the person is allowed to do, limited by the scope | Exactly the role you grant, for the whole tenant |
| Routes | All routes the scope allows | Only the versioned routes (/v1/) |
Only the versioned routes accept an application role. Every other route answers 403 Forbidden to an application token.
A role is never inherited from another product. A role of EasyLife 365 Collaboration or EasyLife 365 Identity opens nothing in EasyLife 365 Mail, and a read role cannot write: a write with a read role answers 403 Forbidden.
Grant the application role
- In the Microsoft Entra admin center, open your application under
App registrations. - Select
API permissions→Add a permission→APIs my organization uses. - Search for EasyLife and select the application named in the table below.
- Select
Application permissionsand select the role you need. - Select
Grant admin consent.
A role that you added but did not consent to has no effect. The role is not in the token, and the API answers 403 Forbidden. Grant the narrowest role that is enough, and never give a role to a person: application roles are for applications only.
The Mail API has two parts. The Admin API is what EasyLife 365 Admin uses. The App API is what the EasyLife 365 Mail app uses. Each part has its own application in your tenant, and the roles live on that application. A token is valid for one API only, so request one token per API.
| API | Application to pick in step 3 | Roles |
|---|---|---|
Admin API: blocklist, manage routes (/admin/mail/v1/...) | EasyLife 365 Admin | Mail.Manage.Read.All, Mail.Manage.ReadWrite.All, Mail.Blocklist.Read.All, Mail.Blocklist.ReadWrite.All |
App API: create routes (/mail/v1/...) | EasyLife 365 Mail | Mail.Mailbox.Provisioning.ReadWrite.All, Mail.DistributionList.Provisioning.ReadWrite.All, Mail.Provisioning.ReadWrite.All |
Register your application and add a credential as described in Create Application Registration.
Get a token
Request the token from your own tenant. The scope is the address of the API you call, plus /.default:
| API | Scope | Application to select in step 3 |
|---|---|---|
Admin API (/admin/mail/v1/...) | https://api.easylife365.cloud/admin/.default | EasyLife 365 Admin |
App API (/mail/v1/...) | https://api.easylife365.cloud/mail/.default | EasyLife 365 Mail |
The examples read the client secret from a file or an environment variable, so it stays out of your shell history, the process list and CI logs. In production, sign in with a certificate instead of a secret. If you use a secret, keep it in a vault and give it a short life.
# secret.txt holds the client secret and nothing else, without a trailing newline.
# Write it from your vault with: printf '%s' "$CLIENT_SECRET" > secret.txt && chmod 600 secret.txt
TOKEN=$(curl -s -X POST "https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "client_id=<client-id>" \
--data-urlencode "client_secret@secret.txt" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "scope=https://api.easylife365.cloud/admin/.default" | jq -r .access_token)
rm secret.txt
Use the scope from the table above for the API you call.
$tenantId = "<tenant-id>"
$scope = "https://api.easylife365.cloud/admin/.default" # create routes: https://api.easylife365.cloud/mail/.default
$body = @{
client_id = "<client-id>"
client_secret = $env:CLIENT_SECRET # or Get-Secret from a secret vault
grant_type = "client_credentials"
scope = $scope
}
$token = (Invoke-RestMethod -Method Post `
-Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" `
-Body $body).access_token
$headers = @{ Authorization = "Bearer $token" }
The response contains an access_token. The curl example keeps only the token in TOKEN; do not log it. Send it as Authorization: Bearer <access_token>. If you use the Insiders version, use api.insiders.easylife365.cloud instead of api.easylife365.cloud in the scope and in every route.
A new client secret can take a few seconds to work. If the token request fails with AADSTS7000215, check that the secret has no trailing newline, then wait and retry.
Routes and roles
Every route, with the delegated scope a signed-in user uses and the application roles that work. Any one of the listed roles is enough.
Blocklist
| Method | Route | API | What it does | Delegated scope | Application roles | Rate limit | Response codes |
|---|---|---|---|---|---|---|---|
GET | /admin/mail/v1/blocklist | Admin API | Read the blocklist | Mail.Blocklist.Read | Mail.Blocklist.Read.All, Mail.Blocklist.ReadWrite.All, Mail.Manage.ReadWrite.All | Read | 200, 401, 403, 429 |
PUT | /admin/mail/v1/blocklist | Admin API | Replace the blocklist | Mail.Blocklist.Write | Mail.Blocklist.ReadWrite.All, Mail.Manage.ReadWrite.All | Create, update, delete | 200, 400, 401, 403, 429 |
See Retrieve the Blocklist and Update the Blocklist.
Manage template and policy
| Method | Route | API | What it does | Delegated scope | Application roles | Rate limit | Response codes |
|---|---|---|---|---|---|---|---|
GET | /admin/mail/v1/manage/mailboxes/{id} | Admin API | Read a shared, room or equipment mailbox | Config.ReadWrite.All | Mail.Manage.Read.All, Mail.Manage.ReadWrite.All | Read | 200, 401, 403, 404, 429 |
PATCH | /admin/mail/v1/manage/mailboxes/{id} | Admin API | Assign or clear the template and policy of a mailbox | Config.ReadWrite.All | Mail.Manage.ReadWrite.All | Create, update, delete | 200, 400, 401, 403, 404, 409, 429 |
GET | /admin/mail/v1/manage/lists/{id} | Admin API | Read a distribution list or mail-enabled security group | Config.ReadWrite.All | Mail.Manage.Read.All, Mail.Manage.ReadWrite.All | Read | 200, 401, 403, 404, 429 |
PATCH | /admin/mail/v1/manage/lists/{id} | Admin API | Assign or clear the template and policy of a list or group | Config.ReadWrite.All | Mail.Manage.ReadWrite.All | Create, update, delete | 200, 400, 401, 403, 404, 409, 429 |
See Manage mailboxes and distribution lists.
Create mailboxes and lists
| Method | Route | API | What it does | Delegated scope | Application roles | Rate limit | Response codes |
|---|---|---|---|---|---|---|---|
POST | /mail/v1/mailboxes | App API | Create a shared, room or equipment mailbox | App.ReadWrite.All | Mail.Mailbox.Provisioning.ReadWrite.All, Mail.Provisioning.ReadWrite.All | Create, update, delete | 200, 400, 401, 403, 404, 429 |
POST | /mail/v1/groups/lists | App API | Create a distribution list or mail-enabled security group | App.ReadWrite.All | Mail.DistributionList.Provisioning.ReadWrite.All, Mail.Provisioning.ReadWrite.All | Create, update, delete | 200, 400, 401, 403, 404, 429 |
See Create Mailbox and Create Distribution List.
Mail.Manage.ReadWrite.All is the broad role of the Admin API routes: the blocklist, and the template and policy of mailboxes and lists. It does not open the create routes, and the create roles do not open the Admin API routes.
Mail.Manage.ReadWrite.All and Mail.Manage.Read.All can read the stored EasyLife data of every shared, room and equipment mailbox, distribution list and mail-enabled security group of your tenant, including owners and the people who confirmed or reviewed a resource. With Mail.Manage.ReadWrite.All, a policy change can also add or remove owners, and the Full Access and Send As that follow from ownership, and an all-zero policy id removes the confirmation and access review of a resource. The role can also replace or clear the blocklist, and that change writes no audit entry. Give the roles only to applications that need them. If an application only handles the blocklist, give it Mail.Blocklist.ReadWrite.All.
Treat every holder of a create role as a privileged identity, and give the roles only to trusted automation. The API does not verify the requestor an application names, and the approver of a request is worked out from that person, so the application decides who is asked to approve. The approver sees the requestor you name, not your application. The application also decides the owners of the new resource and, for a mailbox, who gets permissions such as Full Access and Send As.
Rate limits
Every route has a rate limit per application. Reading has the most generous limit, and creating, changing and deleting (this includes replacing the blocklist) a lower one. When you exceed it, the API answers 429 Too Many Requests with the code RateLimited. Wait a few seconds and send the call again.
Errors
Errors are application/problem+json with a machine-readable code, a title, a detail and a requestId. Branch on code, not on the text. Send the requestId to support when you need help with a failed call.
{
"type": "https://docs.easylife365.cloud/errors/mail/requestor-required",
"title": "A requestor is required for a request that needs approval.",
"status": 400,
"detail": "Send requestorId.",
"code": "Mail.RequestorRequired",
"requestId": "72d2f4b8-76fe-4140-9460-3c7ef9091cb5"
}
The codes that these routes answer with are listed on each page. The most common ones for every route:
| Status | Code | Meaning |
|---|---|---|
| 401 | none | The token is missing, expired or for another API. |
| 403 | none | The token carries no role that this route accepts, the role is a read role on a write, or the route is not a versioned route. |
| 429 | RateLimited | Too many calls. Try again shortly. |
| 500 | InfrastructureError | The call could not be completed. Give support the requestId. |
Audit
Template and policy changes. A change made with an application token is written to the audit log, and the calling application is recorded as the actor. On a mailbox, when the policy check changes an owner, the owner and permission events are written too; see Update template and policy.
Creations. When audit logging is turned on for the tenant, the engine writes one entry when the mailbox or list exists (CREATE-MAILBOX or CREATE-GROUP). In rare cases a mailbox or list exists without an entry, for example when the entry could not be written. The actor of that entry is the EasyLife engine, not your application. The description names the requestor and, for a request made by an application, says "requested by application" followed by its application (client) ID. To find the creations of your automation, search the description, not the application column. A request that fails or is never approved leaves no entry.
Blocklist. Replacing the blocklist writes no audit entry; see Update the Blocklist.