Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Namespace: microsoft.graph
Important
APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Update a resourcePolicyDefinition object.
The service extracts metadata from the updated Rego policy. Updating a definition creates a new current version and moves its previous current version into previousVersions. The new semantic version must be greater than the current version. For example, updating version 1.0.0 to 1.1.0 makes version 1.0.0 available at /admin/resourcePolicy/definitions/{uniqueName}/previousVersions/1.0.0. Existing assignments remain pinned to their referenced version. This method updates customer-authored definitions; built-in definitions are read-only.
Retrieve the current definition and supply its ETag in the If-Match header. A stale ETag causes 412 Precondition Failed; retrieve the latest definition before retrying the update.
For policy structure, metadata, parameters, and examples, see Author policies with Rego.
Permissions
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
| Permission type | Least privileged permissions | Higher privileged permissions |
|---|---|---|
| Delegated (work or school account) | ResourcePolicyDefinition.ReadWrite.All | Not available. |
| Delegated (personal Microsoft account) | Not supported. | Not supported. |
| Application | ResourcePolicyDefinition.ReadWrite.All | Not available. |
Important
For delegated access using work or school accounts, the signed-in user must be assigned a supported Microsoft Entra role or a custom role that grants the permissions required for this operation. Resource Policy Administrator is the least privileged role supported for this operation.
HTTP request
PATCH /admin/resourcePolicy/definitions/{resourcePolicyDefinition-uniqueName}
Request headers
| Name | Description |
|---|---|
| Authorization | Bearer {token}. Required. Learn more about authentication and authorization. |
| Content-Type | application/json or text/plain. Required. |
| If-Match | Required. The current definition's ETag, returned in @odata.etag for JSON or the ETag header for a plain-text GET response. |
Request body
For Content-Type: application/json, supply the following properties. JSON-escape the Rego policy text and supply it as a string in rule.policy.
| Property | Type | Description |
|---|---|---|
| rule | resourcePolicyRule | The Rego policy in rule.policy. The service computes rule.appliesTo and the definition metadata. |
For Content-Type: text/plain, supply the unescaped Rego policy as the entire body.
For either format, the unique name in the request URL must match the unique name in the Rego package. If the JSON body also specifies uniqueName, it must match as well. The package name supplies the new version, such as package graph.require_application_name["1.1.0"]; applicability comes from __metadata__.selector. For details, see resourcePolicyDefinition.
Response
If successful, this method returns 204 No Content with no response body.
Examples
Example 1: Update a definition with JSON
Request
PATCH https://graph.microsoft.com/beta/admin/resourcePolicy/definitions/require_application_name
Content-Type: application/json
If-Match: "972dd856-91ff-4539-be09-50ea8235b76c"
{
"rule": {
"policy": "package graph.require_application_name[\"1.1.0\"]\n\n__metadata__ := {\n \"title\": \"Require an application name\",\n \"description\": \"Require applications to have a display name\",\n \"category\": \"identityAndTenant\",\n \"selector\": {\n \"resourceName\": \"microsoft.graph.application\",\n \"operations\": [\n \"create\",\n \"updateOrUpsert\"\n ]\n }\n}\n\ndefault deny := {\"result\": false, \"reasons\": []}\n\ndeny := {\"result\": true, \"reasons\": [\"A display name is required.\"]} if {\n object.get(input.resource, \"displayName\", \"\") == \"\"\n}\n"
}
}
Response
HTTP/1.1 204 No Content
Example 2: Update a definition with a plain-text policy
The package name identifies the same definition as the request URL and supplies version 1.1.0.
Request
PATCH https://graph.microsoft.com/beta/admin/resourcePolicy/definitions/require_application_name
Content-Type: text/plain
If-Match: "972dd856-91ff-4539-be09-50ea8235b76c"
package graph.require_application_name["1.1.0"]
__metadata__ := {
"title": "Require an application name",
"description": "Require applications to have a display name",
"category": "identityAndTenant",
"selector": {
"resourceName": "microsoft.graph.application",
"operations": ["create", "updateOrUpsert"]
}
}
default deny := {"result": false, "reasons": []}
deny := {"result": true, "reasons": ["A display name is required."]} if {
object.get(input.resource, "displayName", "") == ""
}
Response
HTTP/1.1 204 No Content