Alert This post is over a year old, some of this information may be out of date.

Get the site URL of an Office 365 Group via the Microsoft Graph

post

Update

Since 29/03/2017 I discovered a new API endpoint which makes retrieving the SharePoint site URL even easier. You can read all about it in the following article: Get the SharePoint site behind an Office 365 Group via the Microsoft Graph

Original article

One important piece of information I required for an application which I am currently building is the site URL of the Office 365 Group site. Unfortunately, this piece of information is not provided by the groups details endpoint.

When you call the API to retrieve the group details, you get the following response:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// API endpoint: https://graph.microsoft.com/v1.0/groups/<group-id>

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups/$entity",
    "id": "41525360-8eca-49ce-bcee-b205cd0aa747",
    "classification": null,
    "createdDateTime": null,
    "description": "The Contoso group.",
    "displayName": "Contoso",
    "groupTypes": [
        "Unified"
    ],
    "mail": "[email protected]",
    "mailEnabled": true,
    "mailNickname": "contoso",
    "onPremisesLastSyncDateTime": null,
    "onPremisesSecurityIdentifier": null,
    "onPremisesSyncEnabled": null,
    "proxyAddresses": [
        "SMTP:[email protected]"
    ],
    "renewedDateTime": null,
    "securityEnabled": false,
    "visibility": "Public"
}

This API endpoint already provides you some very useful pieces of information, but nothing about the URL of the SharePoint site.

You might think to compose the site URL yourself with the information you retrieved via the details response. Which in fact is not such a great idea. When a SharePoint site with the same name as the group name already exists. The new group site will get created with a random number at the end. The group name property or mail address will not contain this number. So, you will never be sure if you composed the URL correctly.

From where can you retrieve the site URL?

As I was going through all the API endpoints of a group. I stumbled upon the endpoint of the group drive (the linked document library). This drive endpoint can return a webUrl, which is in fact the URL to the document library of course. One minor thing, if you want to retrieve this piece of information, it requires an additional call. The call itself is easy one:

1
https://graph.microsoft.com/v1.0/groups/<group-id>/drive/root/webUrl

The call will give you the following response:

1
2
3
4
{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups('41525360-8eca-49ce-bcee-b205cd0aa747')/drive/root/webUrl",
    "value": "https://a830edad9050849nda1.sharepoint.com/sites/contoso/Shared%20Documents"
}

In this response, you can see the webUrl value, and as I already mentioned it includes the document library (“Shared Documents”). I think it is safe to presume that you would already know how to get it remove it.

Sample

I also created a sample, so if you want to check out the following GitHub repository: Office365GroupWebUrlViaMicrosoftGraph.

Comments

Back to top