How do we get or retrieve the associated sites in a SharePoint hub site using CSOM or REST API? I don't find API methods for this. Please suggest me a solution.
Thank you.
You can use the REST API below to get information about all hub sites that the current user can access.
/_api/HubSites
Refer to: https://docs.microsoft.com/en-us/sharepoint/dev/features/hub-site/rest-hubsites-method
More information: Hub site REST API
Mikael Svenson has a blog post - you can use the SharePoint Search REST API, querying on the managed property called DepartmentId.
More information available here: https://www.techmikael.com/2018/04/working-with-hub-sites-and-search-api.html
An example of a REST call that returns all sites that are joined to a specific hub site (NOT including the hub site itself):
https://<hostname>/_api/search/query?querytext='contentclass%3dsts_site AND NOT siteid:<hubsite-id> AND departmentid%3d{<hubsite-id>}'&refinementfilters='departmentid:string("{*"%2clinguistics%3doff)'&trimduplicates=false
And an example of the same REST call but this time including the hub site itself:
https://<hostname>/_api/search/query?querytext='contentclass%3dsts_site AND departmentid%3d{<hubsite-id>}'&refinementfilters='departmentid:string("{*"%2clinguistics%3doff)'&trimduplicates=false
<hostname> = host to your sharepoint web app, like contoso.sharepoint.com
<hubsite-id> = id (GUID) of the hub site