How to disable Office Graph and what are the impacts on the REST API

On March 16th, Delve (based on Office Graph) has started rolling out to eligible Office 365 business customers worldwide.

This is a great news for all the users who wants a new way to discover and work with their documents stored in their Office 365 tenant.

But because it’s a brand new way to work, all customers doesn’t necessarily want to offer Delve to all their users for now.

Disable Office Graph on the Office 365 tenant

If you don’t want to use Office Graph in your company, it’s possible to disable it for all the users.

To do it and as a tenant administrator, you have to connect to the SharePoint Admin Center then go the “Settings” section.

In this screen, you just need to check “Don’t allow access to the Office Graph” as you can see in the screenshot below.

Disable Office Graph

Then save your modification and after a short time (from few seconds to few minutes), Delve and Office Graph will be disabled/unusable for all the users of your Office 365 tenant.

Querying the Office Graph with the REST API

Now that we are able to enable/disable the Office Graph at the tenant level, let see how to query it by using the REST API and what happens when the feature was disabled.

For now (Microsoft is working to offer new possibilities/APIs in the future), you have to use the SharePoint search API to query the Office Graph. It’s pretty simple and there’s two different ways to achieve this goal.

My favorite is to POST the query to the search endpoint. The endpoint is accessible from all the SharePoint sites on your tenant.

https://<tenant>.sharepoint.com/_api/search/postquery/
OR
https://<tenant>.sharepoint.com/sites/anotherSiteCollection/_api/search/postquery/

Office Graph queries can be very simple or much more complicated to write, depending on what you want to retrieve. Below, you can see a sample which retrieves the documents (Word, Excel, PowerPoint, PDF and Office 365 Videos) as you can see when you display Delve’s homepage.

{
  "request": {
    "Properties": [
      {
        "Name": "GraphQuery",
        "Value": {
          "QueryPropertyValueTypeIndex": 1,
          "StrVal": "AND(ACTOR(ME,action:1021),ACTOR(ME,OR(action:1021,action:1036,action:1037,action:1039,action:1052)))"
        }
      },
      {
        "Name": "GraphRankingModel",
        "Value": {
          "QueryPropertyValueTypeIndex": 1,
          "StrVal": "action:1021,weight:1,edgeFunc:weight,mergeFunc:max"
        }
      }
    ],
    "QueryTemplate": "({searchterms}) AND ((NOT HideFromDelve:True) AND (FileExtension:doc OR FileExtension:docx OR FileExtension:xls OR FileExtension:xlsx OR FileExtension:ppt OR FileExtension:pptx OR FileExtension:one OR FileExtension:pdf OR ContentTypeId:0x010100F3754F12A9B6490D9622A01FE9D8F012*))",
    "Querytext": "*",
    "RankingModelId": "0c77ded8-c3ef-466d-929d-905670ea1d72",
    "RowLimit": 20,
    "StartRow": 0,
    "Timeout": 30000,
    "TrimDuplicates": true
  }
}

If you want more information about how to build an Office Graph query, please refer to the following MSDN article : https://msdn.microsoft.com/en-us/office/office365/howto/query-Office-graph-using-gql-with-search-rest-api

Execute a query when the Office Graph was disabled

You probably ask yourself : what will happen if we execute the previous query on a tenant from which the Office Graph was disabled ?

As for a lot of things when you use the Office 365 REST API, if you try to use an unavailable feature or if you send malformed data, an exception is thrown and returned to the user.

The Office Graph and the SharePoint search engine work as well. If you try to execute an Office Graph query when the feature is disabled, an exception is thrown. You can see below an example of the server response.

{
  "odata.error": {
    "code": "-1, Microsoft.Office.Server.Search.REST.SearchServiceException",
    "message": {
      "lang": "en-US",
      "value": "Graph queries currently disabled."
    }
  }
}

For now, there’s no REST API to check if the Office Graph feature is enabled or disabled. The only way to check is to execute a query and catch the exception.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s