Monday, May 28, 2018

Set O365 group classification via Graph API

Some time ago MS announced possibility to specify groups classifications – see e.g. Classifications for Office365 Groups and Microsoft Teams. After you configured classifications on tenant level like shown in mentioned article when you go to Sharepoint app from your Office 365 App launcher (it will lead to https://{tenant}.sharepoint.com/_layouts/15/sharepoint.aspx) and choose “+ Create site” from the header – you will see dropdown list with specified classifications:

2018-05-28_17-14-43

When you will create new site classification will be shown in the header:

2018-05-28_17-16-26

Also if you will get related group via Graph API – classification will be returned with other group’s properties:

GET https://graph.microsoft.com/v1.0/groups/{id}/classification

will return

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups('{id}')/classification",
  "value": "internal"
}

But is it possible to update group’s classification programmatically? If we just try to send PACTH request on https://graph.microsoft.com/v1.0/groups/{id} endpoint we will get the following error:

{
    "error": {
        "code": "Request_BadRequest",
        "message": "Property 'classification' is read-only and cannot be set.",
        "innerError": {
            "request-id": "...",
            "date": "2018-05-28T14:22:55"
        }
    }
}

The answer is however yes it is possible: in order to set classification of O365 group via Graph API you need to use beta endpoint instead of v1.0: https://graph.microsoft.com/beta/groups/{id}. In this case property should be successfully updated.

Note that team site classification is stored in own property Site.Classification. So if you updated group’s classification you may also want to update classification of related site. If you use SiteExtension.SetSiteClassification from OfficeDevPnP both actions will be done automatically.

5 comments:

  1. I get error using beta api. Any suggestions?
    {
    "error": {
    "code": "Request_BadRequest",
    "message": "Property classification has an invalid value.",
    "innerError": {
    "request-id": "12ba38ce-44eb-4727-a526-b7e76b1c1625",
    "date": "2018-11-19T11:00:50"
    },
    "details": [
    {
    "target": "classification",
    "code": "InvalidValue"
    }
    ]
    }
    }

    ReplyDelete
  2. Nitesh, ensure that you configured ClassificationList tenant property like shown here: https://joachimloe.com/2018/01/19/classifications-for-office365-groups-and-microsoft-teams/

    ReplyDelete
  3. Replies
    1. For some reason, v1.0 is still not working for me, but beta is.

      Delete