I would like a new cmdlet called Get-PnPRequestDigest to retrieve a fresh request digest value for use in custom REST calls to ODSP.
Alternatively, having the ability to optionally include the X-REQUESTDIGEST header value using the existing Invoke-PnPSPRestMethod (maybe a -IncludeRequestDigestHeader switch) call would be a great enhancement.
Describe the solution you'd like
Would like one or both of the following enhancements:
a. Add a cmdlet like Get-PnPRequestDigest to retrieve a fresh request digest value to use in building manual REST calls
$digest = Get-PnPRequestDigest # <-- NEW REQUEST
$token = Get-PnPAccessToken -ResourceTypeName SharePoint
$headers = @{}
$headers.Accept = "application/json"
$headers."Content-Type" = "application/json"
$headers.Authorization = "Bearer $token"
$headers."X-HTTP-Method" = "MERGE"
$headers."X-REQUESTDIGEST" = $digest
Invoke-RestMethod `
-Method POST `
-Uri "$($Web.Url)/_api/web/RootFolder" `
-Body "{`"WelcomePage`":`"$path`"}" `
-Headers $headers
b. Add an option switch to Invoke-PNPSPRestMethod to automatically include the X-REQUESTDIGEST request header. These would likely also request a new optional parameter to set the X-HTTP-Method header value as well.
Invoke-PnPSPRestMethod `
-Method POST `
-Url "/_api/web/RootFolder" `
-Content $json `
-ContentType "application/json" `
-IncludeRequestDigest `
-XHTTPMethod "MERGE"
Describe alternatives you've considered
Used the following to retrieve the digest value and manually build and executed REST call using Invoke-RestMethod
$context = Get-PnpContext
$digest = [Microsoft.SharePoint.Client.ClientContextExtensions]::GetRequestDigestAsync( $context ).GetAwaiter().GetResult()
Additional context
I needed to set the WelcomePage URL for a few thousand webs, had to use the GetRequestDigestAsync method and build my own REST headers to allow the POST to succeed.
I would like a new cmdlet called Get-PnPRequestDigest to retrieve a fresh request digest value for use in custom REST calls to ODSP.
Alternatively, having the ability to optionally include the X-REQUESTDIGEST header value using the existing Invoke-PnPSPRestMethod (maybe a -IncludeRequestDigestHeader switch) call would be a great enhancement.
Describe the solution you'd like
Would like one or both of the following enhancements:
a. Add a cmdlet like Get-PnPRequestDigest to retrieve a fresh request digest value to use in building manual REST calls
b. Add an option switch to Invoke-PNPSPRestMethod to automatically include the X-REQUESTDIGEST request header. These would likely also request a new optional parameter to set the X-HTTP-Method header value as well.
Describe alternatives you've considered
Used the following to retrieve the digest value and manually build and executed REST call using Invoke-RestMethod
Additional context
I needed to set the WelcomePage URL for a few thousand webs, had to use the GetRequestDigestAsync method and build my own REST headers to allow the POST to succeed.