Validate that a Microsoft 365 group's display name or mail nickname complies with naming policies. Clients can use this API to determine whether a display name or mail nickname is valid before trying to update a Microsoft 365 group. To validate the properties before creating a group, use the directoryobject:validateProperties function.
The following policy validations are performed for the display name and mail nickname properties:
Validate the prefix and suffix naming policy
Validate the custom banned words policy
This API only returns the first validation failure that is encountered. If the properties fail multiple validations, only the first validation failure is returned. However, you can validate both the mail nickname and the display name and receive a collection of validation errors if you are only validating the prefix and suffix naming policy. To learn more about configuring naming policies, see Configure naming policy.
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.
In the request body, provide a JSON object with the following parameters.
Parameter
Type
Description
displayName
String
The display name of the group to validate. The property is not individually required. However, at least one property (displayName or mailNickname) is required.
mailNickname
String
The mail nickname of the group to validate. The property is not individually required. However, at least one property (displayName or mailNickname) is required.
onBehalfOfUserId
Guid
The ID of the user to impersonate when calling the API. The validation results are for the onBehalfOfUserId's attributes and roles.
Response
If successful and there are no validation errors, the method returns 204 No Content response code. It doesn't return anything in the response body.
If the request is invalid, the method returns 400 Bad Request response code. An error message with details about the invalid request is returned in the response body.
If there is a validation error. The method returns 422 Unprocessable Entity response code. An error message and a collection of error details is returned in the response body.
Examples
Example 1: Successful validation request
This is an example of a successful validation request.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Groups.Item.ValidateProperties;
var requestBody = new ValidatePropertiesPostRequestBody
{
DisplayName = "Myprefix_test_mysuffix",
MailNickname = "Myprefix_test_mysuffix",
OnBehalfOfUserId = Guid.Parse("onBehalfOfUserId-value"),
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Groups["{group-id}"].ValidateProperties.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
"github.com/google/uuid"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphgroups "github.com/microsoftgraph/msgraph-sdk-go/groups"
//other-imports
)
requestBody := graphgroups.NewValidatePropertiesPostRequestBody()
displayName := "Myprefix_test_mysuffix"
requestBody.SetDisplayName(&displayName)
mailNickname := "Myprefix_test_mysuffix"
requestBody.SetMailNickname(&mailNickname)
onBehalfOfUserId := uuid.MustParse("onBehalfOfUserId-value")
requestBody.SetOnBehalfOfUserId(&onBehalfOfUserId)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
graphClient.Groups().ByGroupId("group-id").ValidateProperties().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.groups.item.validateproperties.ValidatePropertiesPostRequestBody validatePropertiesPostRequestBody = new com.microsoft.graph.groups.item.validateproperties.ValidatePropertiesPostRequestBody();
validatePropertiesPostRequestBody.setDisplayName("Myprefix_test_mysuffix");
validatePropertiesPostRequestBody.setMailNickname("Myprefix_test_mysuffix");
validatePropertiesPostRequestBody.setOnBehalfOfUserId(UUID.fromString("onBehalfOfUserId-value"));
graphClient.groups().byGroupId("{group-id}").validateProperties().post(validatePropertiesPostRequestBody);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Groups\Item\ValidateProperties\ValidatePropertiesPostRequestBody;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new ValidatePropertiesPostRequestBody();
$requestBody->setDisplayName('Myprefix_test_mysuffix');
$requestBody->setMailNickname('Myprefix_test_mysuffix');
$requestBody->setOnBehalfOfUserId('onBehalfOfUserId-value');
$graphServiceClient->groups()->byGroupId('group-id')->validateProperties()->post($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.groups.item.validate_properties.validate_properties_post_request_body import ValidatePropertiesPostRequestBody
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = ValidatePropertiesPostRequestBody(
display_name = "Myprefix_test_mysuffix",
mail_nickname = "Myprefix_test_mysuffix",
on_behalf_of_user_id = UUID("onBehalfOfUserId-value"),
)
await graph_client.groups.by_group_id('group-id').validate_properties.post(request_body)