You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by EdAlexander August 16, 2024
I am trying to find a pnp.core code equivelant to the PowerShell commandlet "Set-PNPSiteArchiveState". Is there a supported way to do this in c#?
I have tried simple restful call with bearer token but always get "unauthorized" as response.
` using (var sourceContext = context.Clone(new System.Uri(SelectedCase.caseUrl)))
{
using (var httpClient = new HttpClient())
{
var accessToken = await context.AuthenticationProvider
.GetAccessTokenAsync(new Uri("https://{mytennant}.sharepoint.com/.default"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
var requestUri = new Uri("https://{mytennant}-admin.sharepoint.com/_api/SiteArchive/Archive");
var content = new StringContent("{\"siteUrl\":\"https://{mytennant}.sharepoint.com/sites/" + sourceSite + "\"}", System.Text.Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync(requestUri, content);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("Site archived successfully.");
}
else
{
Console.WriteLine($"Failed to archive site. Status code: {response.StatusCode}");
}
}
The text was updated successfully, but these errors were encountered:
Discussed in #1507
Originally posted by EdAlexander August 16, 2024
I am trying to find a pnp.core code equivelant to the PowerShell commandlet "Set-PNPSiteArchiveState". Is there a supported way to do this in c#?
I have tried simple restful call with bearer token but always get "unauthorized" as response.
` using (var sourceContext = context.Clone(new System.Uri(SelectedCase.caseUrl)))
{
The text was updated successfully, but these errors were encountered: