Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archiving SharePoint Online Site #1536

Open
jansenbe opened this issue Sep 18, 2024 Discussed in #1507 · 0 comments
Open

Archiving SharePoint Online Site #1536

jansenbe opened this issue Sep 18, 2024 Discussed in #1507 · 0 comments
Labels
area:admin 📜 Admin library related help wanted Extra attention is needed

Comments

@jansenbe
Copy link
Contributor

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)))
{

            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}");
                }
            }
@jansenbe jansenbe added help wanted Extra attention is needed area:admin 📜 Admin library related labels Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:admin 📜 Admin library related help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant