powershell icon indicating copy to clipboard operation
powershell copied to clipboard

[BUG] - Invoke-PnPSPRestMethod -Method Post needs an empty -Content regardless if no body is required.

Open LeonArmston opened this issue 4 years ago • 2 comments

Reporting an Issue or Missing Feature

Been doing some with with SPO Rest and adding sites to Hubs using Invoke-PnPSPRestMethod Using JoinHubSite which requires no body.

Expected behavior

Rest Command without a body would complete successfully rather than erroring and requiring a blank -Content

to be submitted

Actual behavior

Please describe what you see instead. Please provide samples of output or screenshots.

Does Not Work

Invoke-PnPSPRestMethod -Url "https://contoso.sharepoint.com/sites/customise/_api/site/JoinHubSite('1a843705-5660-4899-ab5b-612233df6eb4')" -Method POST -ContentType "application/json;odata=verbose;charset=utf-8"

image

Does Work after adding -Content @{}

Invoke-PnPSPRestMethod -Url "https://contoso.sharepoint.com/sites/customise/_api/site/JoinHubSite('1a843705-5660-4899-ab5b-612233df6eb4')" -Method POST -ContentType "application/json;odata=verbose;charset=utf-8" -Content @{}

image

Steps to reproduce behavior

Please include complete script or code samples in-line or linked from gists

Get-PnPHubSite #Get a SiteId of a Hub

#Does not work
Invoke-PnPSPRestMethod -Url "https://contoso.sharepoint.com/sites/customise/_api/site/JoinHubSite('1a843705-5660-4899-ab5b-612233df6eb4')" -Method POST -ContentType "application/json;odata=verbose;charset=utf-8"

#Works
Invoke-PnPSPRestMethod -Url "https://contoso.sharepoint.com/sites/customise/_api/site/JoinHubSite('1a843705-5660-4899-ab5b-612233df6eb4')" -Method POST -ContentType "application/json;odata=verbose;charset=utf-8" -Content @{}

What is the version of the Cmdlet module you are running?

(you can retrieve this by executing Get-Module -Name "PnP.PowerShell" -ListAvailable) 1.9.16

Which operating system/environment are you running PnP PowerShell on?

  • [X] Windows
  • [ ] Linux
  • [ ] MacOS
  • [ ] Azure Cloud Shell
  • [ ] Azure Functions
  • [ ] Other : please specify

LeonArmston avatar Jan 25 '22 21:01 LeonArmston

Also the reason I'm having to use SPO Rest to add sites to a SharePoint hub is the PnP cmdlets for Hubs require you to be a SP tenant admin (which I am not in this tenant as it is high security and a shared tenant) whereas with Rest I believe you just need to be a site owner and have permission to join sites to the hub. This is now working fine for me to add sites to the hub in this tenant using -Content @{}

I am a Team Owner (SCA) and have permission to add to the hub.

So perhaps a suggestion would be that the tenant admin check can be removed for the hub cmdlets?

PS - In the UI I dont need to be a tenant admin to add sites to the hub image

LeonArmston avatar Jan 26 '22 09:01 LeonArmston

More complex than I initially thought, still looking into this :)

gautamdsheth avatar Mar 05 '22 15:03 gautamdsheth

hi @LeonArmston, after a few more days :). This is by design.

Lots of APIs differ in their behavior. Some of them require a body, some don't. By adding a default , empty body we might even break existing behavior. So, will not be adding a default body content.

This is also how normal PowerShell web requests work. We only specify the body if it is needed by the request.

gautamdsheth avatar Sep 20 '22 19:09 gautamdsheth