If you work on Office 365, you probably know what are groups, one of the latest features launched by Microsoft on its collaborative platform.
For those who don’t know what’s it, it’s a new way and mostly a simplest way, to create sites that allow users to collaborate with a minimal set of collaborative features such as storing documents, creating conversations, taking notes in a notebook and sharing events on a calendar.
Below you can see an example of a group, especially the document storage.
For now, if you want to find a document in a given group or a set of documents across all groups, there’s no possibility to search what you’re looking for.
Indeed, when you search for documents using the search area available on the top-left (cf. screenshot), you will be redirected to the global search center of your company available in Office 365.
Fortunately, we can use the search engine with REST API to implement that missing feature.
As a reminder (we described it many times in articles on this blog), to submit a search query in Office 365 using REST API, you can send a POST request to the following URL with a well-formatted HTTP body.
https://tenant.sharepoint.com/_api/Search/PostQuery
When you want to retrieve only documents stored in SharePoint libraries, you can filter items based on the ContentClass property which exists for each items (pages, documents, tasks, events…) that were created in your sites.
In the same way, if you want to search only in a particular kind of site (e.g. Office 365 groups in our case), you can filter results based on the SiteTemplate property.
So what looks like the request to send to the REST API ?
{ request = { Querytext = "ContentClass:STS_ListItem_DocumentLibrary AND SiteTemplate:GROUP", RowLimit = 100, SelectProperties = ( Title, DefaultEncodingURL, SiteTitle, SPSiteURL ), StartRow = 0, Timeout = 30000, TrimDuplicates = True } }
In the request above, we return the first 100 documents (excluding duplicates) stored in all Office 365 groups and we also retrieve some additional information such as the title of the documents (Title), the URL of the file (DefaultEncodingURL), the name of the group where it’s stored (SiteTitle) and the URL of the group (SPSiteURL).
If you want to be more precise on your search (e.g. search for documents that have a title which start with the word “Program“), then you can add new filters to your query such as the example below.
Title:Program* AND ContentClass:STS_ListItem_DocumentLibrary AND SiteTemplate:GROUP
As we have seen in this article, it’s pretty simple to search documents across all Office 365 groups and it’s just up to you to integrate and to use REST API in your different applications (mobile, Office add-ins, WebParts…).
Thank for your article.
I’m using Office 365 SDK for iOS, I guess SDK not support searching function in their SDK.
LikeLike
You’re right, the official SDK published by Microsoft doesn’t support searching function and more generally, doesn’t offer SharePoint features (except basic operations on lists).
LikeLike
With SDK, currently, I can:
+ get list files and folders in root folder and sub-folder
+ create folder
+ create file
+ preview file [image, doc,…and something else if UIWebview can load]
In future, I wish, SDK can:
+ search items
+ sort items by name, date, or size.
LikeLike
about search function in SDK, i found this code:
[[[self.client.files search:@”123456″] addCustomParametersWithName:@”Querytext” value:@”sharepoint”] readWithCallback:^(id response, MSOrcError *error) {
NSLog(@””);
}];
But I can’t know how to use correct string in search and correct Parameters and value…
LikeLike
The “search function” that you mentioned doesn’t correspond to the SharePoint search engine. It’s just a convenience method bound to the $search parameter used by REST APIs based on OData.
LikeLike
Pingback: Episode 072 on SharePoint dev with Chris O’Brien—Office 365 Developer Podcast | X-Vision IT Consulting GmbH
Pingback: Episode 072 on SharePoint dev with Chris O’Brien—Office 365 Developer Podcast | Alt-Tech Inc.
Pingback: Episode 072 on SharePoint dev with Chris O’Brien—Office 365 Developer Podcast | Com-Tech of Miami, Inc.