Tuesday, 23 September 2014

Querying Office Graph in SharePoint Online using GQL


Microsoft started rolling out Delve was rolled out to Office 365 customers couple of weeks back. Delve is a new way to find relevant document, people and conversations around them instead of searching for them. Office graph is the technology that powers delve and developers can make use of Office Graph to build custom applications that extend Office 365.
Office Graph has information about people, documents and the relationship and interactions between them. In Office graph terms users who perform activities on documents are actors and the activity they perform is an action. The relationships and interactions are represented as edges and an activity performed by an actor will generate an edge.

Developers can query the Office Graph in SharePoint online through search REST API by passing GraphQuery property to search API. The Graph Query Language (GQL) has the syntax of
GraphQuery:actor(<ActorID>,[filter])

Where ActorID is the ID of the actor for which you want to retrieve activities and documents and filter is an optional argument of action types to filter the results based on activities performed. For example to query all modifications done by an actor with ActorID of 1009 the GQL would be

https://<SharePoint Online site>/_api/search/query/?QueryText=’*’&Properties=’GraphQuery:actor(1009\,action\:1003)’

https://slmfeo13052.sharepoint.com/_ api/search/query/?QueryText=’*’&Properties=’GraphQuery:actor(ME, action\:1003)’

Where 1003 is the action ID that represents modify action. Full list of action types can be seen from here. 
Results returned from GQL are similar to the results from SharePoint Search REST API except that and additional property called Edges will be included in the details.   Edges property will have details of action, date and ranking model weight. Following is an example of Edges property returned from a GQL Search REST API call
 <d:element m:type="SP.KeyValue">
<d:Key>Edges</d:Key>
<d:Value>[{"ActorId":29355180,"ObjectId":28029928,"Properties":{"Action":1001,"Blob":[],"BlobContent":"","ObjectSource":1,"Time":"2014-09-12T09:47:17.0000000Z","Weight":1}}]</d:Value>
<d:ValueType>Edm.String</d:ValueType>
</d:element>

Using GQL and the Edges property interesting application can be developed as shown by Richard’s MSDN blog .

No comments:

Post a Comment