Mar 12 2018 04:23 AM
Hi,
How to show the Site Collection List which is accessible to the user using SharePoint Framework Client Side Web Part in Office 365?
Please provide a example.
Thanks in advance.
Mar 12 2018 04:42 AM - edited Mar 12 2018 04:44 AM
SolutionYou can achieve this by making use the Search REST API:
You can specify your search query to retrieve site collections:
contentclass:"STS_Site"
See also:
Mar 12 2018 06:45 AM
Hi Paul,
Thanks for the reply.
However, I am not able to get the Site Collection List using the _getListData() method in GetSiteCollectionListWebPart.ts in O365 using SharePoint Framework (SPFx):
export interface ISiteCollectionLists {
value: ISiteCollectionList[];
}
export interface ISiteCollectionList {
SiteCollectionName: string;
SiteCollectionUrl: string;
}
private _getListData(): Promise<ISiteCollectionLists> {
return this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + "/_api/search/query?querytext='contentclass:sts_site'", SPHttpClient.configurations.v1)
.then((response) => {
return response.json();
});
}
Please let me know the corrections to be made in _getListData() method.
Thanks in advance.
Mar 12 2018 12:34 PM
I noticed a HTTP 500 server error occurs in your code. This has to do with the OData version being supporoted by SP Search REST API. After changing your _getListData method as below I got it working:
private _getListData(): Promise<ISiteCollectionLists> { const spSearchConfig: ISPHttpClientConfiguration = { defaultODataVersion: ODataVersion.v3 }; return this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + "/_api/search/query?querytext='contentclass:sts_site'", SPHttpClient.configurations.v1.overrideWith(spSearchConfig)) .then((response) => { return response.json(); }); }
You have to import some additional types for the above to work, see the blog below for details:
http://www.vrdmn.com/2017/01/working-with-rest-api-in-sharepoint.html
Hope this helps!
Mar 13 2018 12:05 AM
How do I parse the XML returned by "/_api/search/query?querytext='contentclass:sts_site" & convert it into JSON?
Mar 13 2018 12:52 AM
Mar 12 2018 04:42 AM - edited Mar 12 2018 04:44 AM
SolutionYou can achieve this by making use the Search REST API:
You can specify your search query to retrieve site collections:
contentclass:"STS_Site"
See also: