SharePoint Online Hub Search - How do you call the search API and limit results to content contained

Highlighted
Contributor

I am writing a web part that is surfacing all news pages on sites associated to a hub which have been tagged with a particular category (through page properties).

 

How do I limit the results of my call to the Search API to only include content from sites associated to the hub?

 

Do I have to first make calls to determine the sites associated to the hub (as per Mikael Svenson's post: https://www.techmikael.com/2018/04/working-with-hub-sites-and-search-api.html) and then use them in my query for news items, or is there an easier way?

 

I cannot see any "Result Sources" that have been created by creating the hub, and I don't really want to have to manually maintain one as sites are associated/disassociated to the hub

 

Thanks!

 

1 Reply
Highlighted

@Nigel Witherdin Check out the Hub Site API.

You'll want to call
_api/Hubsites?filter=SiteUrl eq "<Your hubsite url>"

It will return the ID. This ID you can use in your Search Query as the DepartmentId to search within your hub.