Pnpjs: Support of Tenant (Admin) REST API methods

Created on 20 Feb 2020  路  10Comments  路  Source: pnp/pnpjs

Category

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

Version

Please specify what version of the library you are using: 2.0.3

Please specify what version(s) of SharePoint you are targeting: Online

Expected / Desired Behavior / Question

The idea is to propose tenant scoped functions that are available in the REST API like:

  • delete a site
  • restore a deleted site
  • getting site properties without creating a Web instance
  • check tenant licences
  • ...

It could be requested like this : sp.tenant.getSitePropertiesByUrl('https://contoso.sharepoint.com/sites/hr', true)

The library will be able to setup an instance to the Admin Site in the background if not exists, so that each method called will refer to the Admin Site instance.

Possible ? Relevant ?

code contribution opportunity馃悋 enhancement

Most helpful comment

Def possible - been a bit since I checked what is actually exposed via REST from that API. I think re-checking that would be a first step to see what we could effectively surface.

All 10 comments

Def possible - been a bit since I checked what is actually exposed via REST from that API. I think re-checking that would be a first step to see what we could effectively surface.

Great, I'll have a look and let you know if you want.

Thanks @michaelmaillot - I will be on leave so please don't be discouraged if I don't respond immediately. Excited to see what we can support here.

Wow, that is exactly what I need right now (I think). I want to set the external sharing property of a site.

In Powershell we do it like

Set-PnPTenantSite -Url $sharepointurl -sharing "ExistingExternalUserSharingOnly"

Is there any other pnpjs or other way to achieve this?

Hi @mplwork !

I know there's an endpoint for this : _https://contoso-admin.sharepoint.com/_api/Microsoft.Online.SharePoint.TenantAdministration.SiteProperties("https://contoso.sharepoint.com/sites/blog")/Update_

Reference here.

You can also achieve this through CSOM (example here).

But I didn't try it.

Hi @mplwork !

I know there's an endpoint for this : _https://contoso-admin.sharepoint.com/_api/Microsoft.Online.SharePoint.TenantAdministration.SiteProperties("https://contoso.sharepoint.com/sites/blog")/Update_

Reference here.

Thanks very much for the link but I can't get it to work. What is the actual URL?

I tried

https://mytenant-admin.sharepoint.com/_api/Microsoft.Online.SharePoint.TenantAdministration.SiteProperties("https://mytenant.sharepoint.com/sites/og_0002")/Update

but whatever I try (with /Update or without) I get a

Microsoft.SharePoint.Client.InvalidClientQueryException.

"The expression "Microsoft.Online.SharePoint.TenantAdministration.SiteProperties("https:/mytenant.sharepoint.com/sites/og_0002")/Update" is not valid."

My token is apparently working as I first tried without a scope for mytenant-admin.sharepoint.com and got a corresponding error.

As working on the CLI for M365, I tried to use some Tenant REST API methods (such as restoring / removing deleted sites), but as it returns SpoOperation objects that doesn't give any identifier to check the status of the execution, I eventually had to use CSOM (eg client.svc) instead.

So to answer @mplwork, the only thing I noticed is that you have to replace double quotes by simple quotes in the URL of the query. Instead of the error you described (which says your query is invalid), you'll have an Microsoft.Online.SharePoint.Common.SpoException 500 error message : _The site Uri provided is null._ Don't know what to do with that anyway and what's missing since it's not documented.

My suggestion would be to use CSOM approach and to give you another implementation, I suggest you to have a look at what has been coded for the spo site classic set command. The source code for that is here.

So, to init the implementation in PnP JS, a first approach would be to reuse the commands used in the CLI, based on CSOM, that we are sure are working. Here's a list:

  • Get / Set properties on a specific site from the Tenant instance (Site Properties like LockState, AllowEditing, Sharing Capability,..)
  • Get / Set properties on the Tenant instance (like OneDriveStorageQuota, UserVoiceForFeedbackEnabled,...)
  • Get list of deleted sites
  • Restore a deleted site
  • Remove a deleted site
  • Get Tenant Id
  • Get Tenant App Catalog

What do you think about that?

I would prefer strongly we not add CSOM calls to PnPjs.

Ok, so if we keep in mind the approach by REST API, there a many operations that are available. Below a list of endpoints with which we could start:

  • _api/Microsoft.Online.SharePoint.TenantManagement.Office365Tenant

    • Properties like "AllowGuestUserShareToUsersNotInSiteCollection", "ExternalServicesEnabled", "GuestSharingGroupAllowList"

    • Methods like "GetExternalUsers", "GetAllTenantThemes"

  • _api/Microsoft.Online.SharePoint.TenantAdministration.SiteProperties

    • Get method on root endpoint

  • _api/Microsoft.Online.SharePoint.TenantAdministration.Tenant

    • Similar properties as _api/Microsoft.Online.SharePoint.TenantManagement.Office365Tenant

    • Methods like "RemoveDeletedSites", "RestoreDeletedSites"

The complexity is about making some queries to work, as they're not documented and when executing them, I got error responses without details like the one mentioned in my previous comment.

Does anyone have detailed info about those APIs or how to query them correctly ?

@michaelmaillot - I don't have details off the top of my head but when I have some time I can investigate, though unsure how soon that will be. Welcome other's input as well

Was this page helpful?
0 / 5 - 0 ratings