Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions documentation/Invoke-PnPGraphMethod.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ This example retrieves a Planner task to find the etag value which is required t
### EXAMPLE 9
```powershell
$batch = New-PnPBatch -RetainRequests
Invoke-PnPSPRestMethod -Method Get -Url "users" -Batch $batch
Invoke-PnPSPRestMethod -Method Get -Url "groups" -Batch $batch
Invoke-PnPGraphMethod -Method Get -Url "users" -Batch $batch
Invoke-PnPGraphMethod -Method Get -Url "groups" -Batch $batch
$response = Invoke-PnPBatch $batch -Details
$response
```
Expand Down
15 changes: 3 additions & 12 deletions src/Commands/Graph/InvokeGraphMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Net.Http.Headers;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;

namespace PnP.PowerShell.Commands.Base
{
Expand Down Expand Up @@ -352,22 +353,12 @@ private void CallBatchRequest(HttpMethod method, string requestUrl)
extraHeaders.Add("Content-Type", ContentType);

ApiRequestType apiRequestType = ApiRequestType.Graph;
if (requestUrl.IndexOf("/beta/", StringComparison.InvariantCultureIgnoreCase) > -1)
if (requestUrl.IndexOf("/beta/", StringComparison.InvariantCultureIgnoreCase) > -1 || requestUrl.StartsWith("beta/", StringComparison.InvariantCultureIgnoreCase))
{
apiRequestType = ApiRequestType.GraphBeta;
}

if (requestUrl.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
{
if (requestUrl.IndexOf("/v1.0/", StringComparison.InvariantCultureIgnoreCase) > -1)
{
requestUrl = requestUrl.Replace($"https://{Connection.GraphEndPoint}/v1.0/", "", StringComparison.InvariantCultureIgnoreCase);
}
else if (requestUrl.IndexOf("/beta/", StringComparison.InvariantCultureIgnoreCase) > -1)
{
requestUrl = requestUrl.Replace($"https://{Connection.GraphEndPoint}/beta/", "", StringComparison.InvariantCultureIgnoreCase);
}
}
requestUrl = Regex.Replace(requestUrl, $"^(https://{Connection.GraphEndPoint})*/*(v1.0|beta)/", "", RegexOptions.IgnoreCase);

web.WithHeaders(extraHeaders).ExecuteRequestBatch(Batch.Batch, new ApiRequest(method, apiRequestType, requestUrl, contentString));
}
Expand Down
Loading