Pnpjs: How to Access a group team site

Created on 18 Nov 2020  路  4Comments  路  Source: pnp/pnpjs

Category

  • [ ] Enhancement
  • [ ] Bug
  • [x] Question
  • [ ] Documentation gap/issue

Version

Please specify what version of the library you are using: [2.0.12]

Please specify what version(s) of SharePoint you are targeting: [SPO]

Question

I would like to find the URL of the team site associated for a group.
I can see that there is a Graph API here. But couldn't find the appropriate method for this in the pnpjs group class.

Question 1

I am using the below code to currently get the team site url of a group

import { graph, GraphHttpClient } from '@pnp/graph';
import '@pnp/graph/groups';
...
...
const graphClient = new GraphHttpClient();
resp = await (await graphClient.get(`https://graph.microsoft.com/${graph.groups.getById("<<GROUP ID>>").toUrl()}/sites/root`)).json();
const teamSiteUrl = resp.webUrl;

Is there a better way to do it?

Question 2

If its not already present, can we add a new method in pnpjs
Something like - _graph.groups.getById("{GROUP ID}").rootSite()_

If this is allowed, I am interested to work on the new method and submit a PR.

code in progress enhancement

All 4 comments

If there is missing functionality you are not only allowed but encouraged to submit a PR! Please do, we will be happy to review it and if you have questions I'll leave this thread open so we can assist as needed.

You can also check out the contributors guide to get started. Only thing I'd note is to also include a test and update the docs with your change.

Welcome aboard!

Thank you for the quick response @patrick-rodgers
I have submitted few PRs earlier for PnPjs V2 and always ready to contribute.

My question was, if the method definition I proposed is on the right class?

Here is the graph API for getting the team site url
GET /groups/{group-id}/sites/root - This returns the team site details for the group

But, GET /groups/{group-id}/sites doesn't return any details.

So, should we call the new method graph.groups.getById("{GROUP ID}").rootSite() or graph.groups.getById("{GROUP ID}").sites.root()

Submitted a PR. Waiting for the review comments

Thanks we'll have a look and try and get it into the next release.

Was this page helpful?
0 / 5 - 0 ratings