// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new SharePointProtectionPolicy
{
DisplayName = "SharePoint Protection Policy",
SiteProtectionUnits = new List<SiteProtectionUnit>
{
new SiteProtectionUnit
{
SiteId = "contoso.sharepoint.com,febad3c2-a7b2-454c-8910-272c7bcf78fc,ba7b70d0-8ba0-4cae-b19a-7cb8c739512f",
},
new SiteProtectionUnit
{
SiteId = "contoso.sharepoint.com/sites/marketing,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740",
},
new SiteProtectionUnit
{
SiteId = "contoso.sharepoint.com/sites/hr,3bfc861e-9a17-4a27-9562-3d8b26c81bb5,0271110f-634f-4300-a841-3a8a2e851851",
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Solutions.BackupRestore.SharePointProtectionPolicies.PostAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
SharePointProtectionPolicy sharePointProtectionPolicy = new SharePointProtectionPolicy();
sharePointProtectionPolicy.setDisplayName("SharePoint Protection Policy");
LinkedList<SiteProtectionUnit> siteProtectionUnits = new LinkedList<SiteProtectionUnit>();
SiteProtectionUnit siteProtectionUnit = new SiteProtectionUnit();
siteProtectionUnit.setSiteId("contoso.sharepoint.com,febad3c2-a7b2-454c-8910-272c7bcf78fc,ba7b70d0-8ba0-4cae-b19a-7cb8c739512f");
siteProtectionUnits.add(siteProtectionUnit);
SiteProtectionUnit siteProtectionUnit1 = new SiteProtectionUnit();
siteProtectionUnit1.setSiteId("contoso.sharepoint.com/sites/marketing,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740");
siteProtectionUnits.add(siteProtectionUnit1);
SiteProtectionUnit siteProtectionUnit2 = new SiteProtectionUnit();
siteProtectionUnit2.setSiteId("contoso.sharepoint.com/sites/hr,3bfc861e-9a17-4a27-9562-3d8b26c81bb5,0271110f-634f-4300-a841-3a8a2e851851");
siteProtectionUnits.add(siteProtectionUnit2);
sharePointProtectionPolicy.setSiteProtectionUnits(siteProtectionUnits);
SharePointProtectionPolicy result = graphClient.solutions().backupRestore().sharePointProtectionPolicies().post(sharePointProtectionPolicy);
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.share_point_protection_policy import SharePointProtectionPolicy
from msgraph.generated.models.site_protection_unit import SiteProtectionUnit
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = SharePointProtectionPolicy(
display_name = "SharePoint Protection Policy",
site_protection_units = [
SiteProtectionUnit(
site_id = "contoso.sharepoint.com,febad3c2-a7b2-454c-8910-272c7bcf78fc,ba7b70d0-8ba0-4cae-b19a-7cb8c739512f",
),
SiteProtectionUnit(
site_id = "contoso.sharepoint.com/sites/marketing,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740",
),
SiteProtectionUnit(
site_id = "contoso.sharepoint.com/sites/hr,3bfc861e-9a17-4a27-9562-3d8b26c81bb5,0271110f-634f-4300-a841-3a8a2e851851",
),
],
)
result = await graph_client.solutions.backup_restore.share_point_protection_policies.post(request_body)