Skip to main content
Version: 1.23.22

Change Application Policy

Professional

The EasyLife 365 Identity API lets you assign a policy to one application, or clear the policy assigned to it. It does the same as Change policy in the Admin Portal, for a script or an integration that has no signed-in person. The answer is the state of the application after the change, in the same shape as Get Application Policy State.

Permissions​

Permission TypePermissions (Scope)
Delegated (work or school account)https://api.easylife365.cloud/admin/Config.ReadWrite.All
Applicationhttps://api.easylife365.cloud/admin/Identity.Manage.ReadWrite.All
warning

Identity.Manage.Read.All does not grant access to this endpoint, because it only reads. A call with it answers 403 Forbidden. Identity.Ownership.ReadWrite.All does not open this endpoint either: roles do not include one another.

note

Application permissions always require admin consent. See Create Application Registration for the app-only setup. Identity.Manage.ReadWrite.All also reads, and it also opens the ownership and owner permissions calls, so grant it only to an integration that needs all of them.

HTTP Request​

PATCH https://api.easylife365.cloud/admin/identity/v1/manage/apps/{id}
Content-Type: application/json
ParameterDescription
idThe Entra Object ID of the application registration or enterprise application. Not its Application (client) ID.

HTTP request headers​

HeaderValue
AuthorizationBearer token. (Required)
Content-Typeapplication/json

Request Body​

PropertyTypeDescription
policyIdString (GUID)Required. The id of the policy to assign. It has to be an active policy for the same type of application. The empty id 00000000-0000-0000-0000-000000000000 clears the assigned policy.
appTypeString or numberRequired. appRegistration or enterpriseApplication, or 0 or 1.

Clearing a policy returns the application to the default policy of your tenant for its type, when there is an active one.

Response​

A successful request returns 200 OK with the state after the change.

PropertyTypeDescription
idStringThe Entra Object ID of the application.
displayNameStringThe display name of the application in Entra.
isCompliantBooleanWhether the application meets the assigned policy. Right after the change, true can mean that it has not been checked yet: read it again later before you rely on it. Left out after a clear, and while the inactivity rule is paused because the tenant's sign-in data is not current and no other rule fails.
policyObjectThe policy data stored for the application, as Get Application Policy State describes it. Left out after a clear.

Sending the same request again is safe: it answers 200 OK with the same state. The keys inside policy can change without notice, so do not build on them.

Errors​

Errors are application/problem+json. Read code: it names the error and does not change. See Errors for the format. A refused request changes nothing.

StatuscodeWhen
400 Bad RequestInvalidPayloadThe body is empty or not valid JSON, appType or policyId is missing. The detail explains which.
400 Bad RequestIdentity.PolicyTargetMismatchThe policy is for the other type of application. The detail names both types.
401 UnauthorizedAuthenticationRequiredThe token is missing, expired or for another API.
403 ForbiddenNotAllowedThe token carries none of the permissions above, for example only Identity.Manage.Read.All, or the token was requested before admin consent.
403 ForbiddenIdentity.LicenseRequiredThe tenant does not have a Professional or Trial license.
404 Not FoundNotFoundNo application of this type has this Object ID in your tenant.
404 Not FoundIdentity.PolicyNotFoundThe policy does not exist.
409 ConflictIdentity.PolicyInactiveThe policy is not active. Activate it in the Admin Portal or choose another one.
429 Too Many RequestsnoneToo many requests. The answer is a short text with a Retry-After header, not a JSON body. Wait and retry. This route uses the limit for bulk operations.
500 Internal Server ErrorInfrastructureErrorThe policy may not have been changed. Read the application with Get Application Policy State. If the policy is not the one you sent, send the request again, and give support the requestId if it keeps failing.

Audit history​

When audit logging is turned on for the tenant, each change is recorded in the application's audit history, with the previous and the new policy. An application making the call is identified by its Application (client) ID, a person by their account. See Logging.

Example 1: Assign a policy​

This example assigns the policy 3d2c8f4e-7a1b-4c59-9e0d-6b5a1f2c8d74 to the app registration with Object ID 57523d68-2913-4fc0-8f91-af100f37562f.

Request​

PATCH https://api.easylife365.cloud/admin/identity/v1/manage/apps/57523d68-2913-4fc0-8f91-af100f37562f
Content-Type: application/json
{
"policyId": "3d2c8f4e-7a1b-4c59-9e0d-6b5a1f2c8d74",
"appType": "appRegistration"
}

Response​

{
"id": "57523d68-2913-4fc0-8f91-af100f37562f",
"displayName": "Contoso Invoicing",
"isCompliant": true,
"policy": {
"pId": "3d2c8f4e-7a1b-4c59-9e0d-6b5a1f2c8d74",
"owSta": "compliant",
"toSta": "compliant",
"boSta": "compliant",
"inSta": "compliant",
"bcSta": "compliant"
}
}

Example 2: Clear the policy​

Request​

PATCH https://api.easylife365.cloud/admin/identity/v1/manage/apps/57523d68-2913-4fc0-8f91-af100f37562f
Content-Type: application/json
{
"policyId": "00000000-0000-0000-0000-000000000000",
"appType": "appRegistration"
}

Response​

{
"id": "57523d68-2913-4fc0-8f91-af100f37562f",
"displayName": "Contoso Invoicing"
}

Example 3: A policy that is not active​

Response​

409 Conflict. Nothing was changed.

{
"type": "https://docs.easylife365.cloud/errors/identity/policy-inactive",
"title": "The policy is not active.",
"status": 409,
"detail": "The policy is not active.",
"code": "Identity.PolicyInactive",
"requestId": "c0a8d1f6-2b47-4e39-b5d2-7e91a4f63c08"
}

Example 4: A policy for the other type of application​

A policy made for enterprise applications was sent for an app registration.

Response​

400 Bad Request. Nothing was changed.

{
"type": "https://docs.easylife365.cloud/errors/identity/policy-target-mismatch",
"title": "The policy is for a different type of application than this one.",
"status": 400,
"detail": "The policy is for enterprise applications, not for app registrations.",
"code": "Identity.PolicyTargetMismatch",
"requestId": "9e2f5a10-6d83-4c17-a4b9-31f8c7d0e256"
}

Example 5: Assign a policy using curl and PowerShell​

In the bash example, set TENANT_ID, CLIENT_ID, CLIENT_SECRET and SCOPE (https://api.easylife365.cloud/admin/.default) first. Before you run them, register an application with Identity.Manage.ReadWrite.All and note its tenant ID, client ID and client secret.

TOKEN=$(curl -s -X POST "https://login.microsoftonline.com/$TENANT_ID/oauth2/v2.0/token" \
-d "client_id=$CLIENT_ID" -d "client_secret=$CLIENT_SECRET" \
-d "grant_type=client_credentials" -d "scope=$SCOPE" | jq -r .access_token)

curl -s -X PATCH "https://api.easylife365.cloud/admin/identity/v1/manage/apps/57523d68-2913-4fc0-8f91-af100f37562f" \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{ "policyId": "3d2c8f4e-7a1b-4c59-9e0d-6b5a1f2c8d74", "appType": "appRegistration" }'
$ErrorActionPreference = "Stop" # stop on a refused or failed request
$tenantId = "[TENANT_ID]"
$clientId = "[CLIENT_ID]"
$clientSecret = "[CLIENT_SECRET]" # read it from your secret store, never hard-code it
$scope = "[SCOPE]" # the .default scope from Create Application Registration
$uri = "[URI]" # the request URL above, with your Object ID

$token = Invoke-RestMethod -Method POST `
-Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" `
-ContentType "application/x-www-form-urlencoded" `
-Body @{ client_id = $clientId; client_secret = $clientSecret; grant_type = "client_credentials"; scope = $scope }

$headers = @{
"Authorization" = "Bearer $($token.access_token)"
"Content-Type" = "application/json"
}

$body = @{ policyId = "3d2c8f4e-7a1b-4c59-9e0d-6b5a1f2c8d74"; appType = "appRegistration" } | ConvertTo-Json

$state = Invoke-RestMethod -Method PATCH -Uri $uri -Headers $headers -Body $body
"$($state.displayName): compliant = $($state.isCompliant)"