Espace de noms: microsoft.graph
Importante
Les API sous la version /beta
dans Microsoft Graph sont susceptibles d’être modifiées. L’utilisation de ces API dans des applications de production n’est pas prise en charge. Pour déterminer si une API est disponible dans v1.0, utilisez le sélecteur Version .
Créez une stratégie de protection pour le service OneDrive dans Microsoft 365. Lorsque la stratégie est créée, son état est défini sur inactive
. Les utilisateurs peuvent également fournir une liste d’unités de protection sous la stratégie.
Cette API est disponible dans les déploiements de cloud national suivants.
Service global |
Gouvernement des États-Unis L4 |
Us Government L5 (DOD) |
Chine gérée par 21Vianet |
✅ |
❌ |
❌ |
❌ |
Autorisations
Choisissez l’autorisation ou les autorisations marquées comme moins privilégiées pour cette API. Utilisez une autorisation ou des autorisations privilégiées plus élevées uniquement si votre application en a besoin. Pour plus d’informations sur les autorisations déléguées et d’application, consultez Types d’autorisations. Pour en savoir plus sur ces autorisations, consultez les informations de référence sur les autorisations.
Type d’autorisation |
Autorisations avec privilèges minimum |
Autorisations privilégiées plus élevées |
Déléguée (compte professionnel ou scolaire) |
BackupRestore-Configuration.ReadWrite.All |
Non disponible. |
Déléguée (compte Microsoft personnel) |
Non prise en charge. |
Non prise en charge. |
Application |
BackupRestore-Configuration.ReadWrite.All |
Non disponible. |
Requête HTTP
POST /solutions/backupRestore/oneDriveForBusinessProtectionPolicies
Corps de la demande
Vous pouvez spécifier les propriétés suivantes lors de la création d’un oneDriveForBusinessProtectionPolicy.
Propriété |
Type |
Description |
displayName |
Chaîne |
Nom de la stratégie de protection SharePoint. Obligatoire |
driveProtectionUnits |
Collection(driveProtectionUnit) |
Collection de driveProtectionUnit à ajouter à oneDriveForBusinessProtectionPolicy. Obligatoire. |
Réponse
Si elle réussit, cette méthode renvoie un 201 Created
code de réponse et un objet oneDriveForBusinessProtectionPolicy dans le corps de la réponse.
Pour obtenir la liste des réponses d’erreur possibles, consultez Réponses d’erreur de l’API de stockage de sauvegarde.
Exemples
Demande
L’exemple suivant illustre une demande.
POST https://graph.microsoft.com/beta/solutions/backupRestore/oneDriveForBusinessProtectionPolicies
{
"displayName": "OneDrive For Business Protection Policy",
"driveProtectionUnits": [
{
"directoryObjectId": "cdd3a849-dcaf-4a85-af82-7e39fc14019"
},
{
"directoryObjectId": "9bc069da-b746-41a4-89ab-26125c6373c7"
},
{
"directoryObjectId": "b218eb4a-ea72-42bd-8f0b-d0bbf794bec7"
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new OneDriveForBusinessProtectionPolicy
{
DisplayName = "OneDrive For Business Protection Policy",
DriveProtectionUnits = new List<DriveProtectionUnit>
{
new DriveProtectionUnit
{
DirectoryObjectId = "cdd3a849-dcaf-4a85-af82-7e39fc14019",
},
new DriveProtectionUnit
{
DirectoryObjectId = "9bc069da-b746-41a4-89ab-26125c6373c7",
},
new DriveProtectionUnit
{
DirectoryObjectId = "b218eb4a-ea72-42bd-8f0b-d0bbf794bec7",
},
},
};
// 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.OneDriveForBusinessProtectionPolicies.PostAsync(requestBody);
mgc-beta solutions backup-restore one-drive-for-business-protection-policies create
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewOneDriveForBusinessProtectionPolicy()
displayName := "OneDrive For Business Protection Policy"
requestBody.SetDisplayName(&displayName)
driveProtectionUnit := graphmodels.NewDriveProtectionUnit()
directoryObjectId := "cdd3a849-dcaf-4a85-af82-7e39fc14019"
driveProtectionUnit.SetDirectoryObjectId(&directoryObjectId)
driveProtectionUnit1 := graphmodels.NewDriveProtectionUnit()
directoryObjectId := "9bc069da-b746-41a4-89ab-26125c6373c7"
driveProtectionUnit1.SetDirectoryObjectId(&directoryObjectId)
driveProtectionUnit2 := graphmodels.NewDriveProtectionUnit()
directoryObjectId := "b218eb4a-ea72-42bd-8f0b-d0bbf794bec7"
driveProtectionUnit2.SetDirectoryObjectId(&directoryObjectId)
driveProtectionUnits := []graphmodels.DriveProtectionUnitable {
driveProtectionUnit,
driveProtectionUnit1,
driveProtectionUnit2,
}
requestBody.SetDriveProtectionUnits(driveProtectionUnits)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
oneDriveForBusinessProtectionPolicies, err := graphClient.Solutions().BackupRestore().OneDriveForBusinessProtectionPolicies().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
OneDriveForBusinessProtectionPolicy oneDriveForBusinessProtectionPolicy = new OneDriveForBusinessProtectionPolicy();
oneDriveForBusinessProtectionPolicy.setDisplayName("OneDrive For Business Protection Policy");
LinkedList<DriveProtectionUnit> driveProtectionUnits = new LinkedList<DriveProtectionUnit>();
DriveProtectionUnit driveProtectionUnit = new DriveProtectionUnit();
driveProtectionUnit.setDirectoryObjectId("cdd3a849-dcaf-4a85-af82-7e39fc14019");
driveProtectionUnits.add(driveProtectionUnit);
DriveProtectionUnit driveProtectionUnit1 = new DriveProtectionUnit();
driveProtectionUnit1.setDirectoryObjectId("9bc069da-b746-41a4-89ab-26125c6373c7");
driveProtectionUnits.add(driveProtectionUnit1);
DriveProtectionUnit driveProtectionUnit2 = new DriveProtectionUnit();
driveProtectionUnit2.setDirectoryObjectId("b218eb4a-ea72-42bd-8f0b-d0bbf794bec7");
driveProtectionUnits.add(driveProtectionUnit2);
oneDriveForBusinessProtectionPolicy.setDriveProtectionUnits(driveProtectionUnits);
OneDriveForBusinessProtectionPolicy result = graphClient.solutions().backupRestore().oneDriveForBusinessProtectionPolicies().post(oneDriveForBusinessProtectionPolicy);
const options = {
authProvider,
};
const client = Client.init(options);
const oneDriveForBusinessProtectionPolicy = {
displayName: 'OneDrive For Business Protection Policy',
driveProtectionUnits: [
{
directoryObjectId: 'cdd3a849-dcaf-4a85-af82-7e39fc14019'
},
{
directoryObjectId: '9bc069da-b746-41a4-89ab-26125c6373c7'
},
{
directoryObjectId: 'b218eb4a-ea72-42bd-8f0b-d0bbf794bec7'
}
]
};
await client.api('/solutions/backupRestore/oneDriveForBusinessProtectionPolicies')
.version('beta')
.post(oneDriveForBusinessProtectionPolicy);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\OneDriveForBusinessProtectionPolicy;
use Microsoft\Graph\Beta\Generated\Models\DriveProtectionUnit;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new OneDriveForBusinessProtectionPolicy();
$requestBody->setDisplayName('OneDrive For Business Protection Policy');
$driveProtectionUnitsDriveProtectionUnit1 = new DriveProtectionUnit();
$driveProtectionUnitsDriveProtectionUnit1->setDirectoryObjectId('cdd3a849-dcaf-4a85-af82-7e39fc14019');
$driveProtectionUnitsArray []= $driveProtectionUnitsDriveProtectionUnit1;
$driveProtectionUnitsDriveProtectionUnit2 = new DriveProtectionUnit();
$driveProtectionUnitsDriveProtectionUnit2->setDirectoryObjectId('9bc069da-b746-41a4-89ab-26125c6373c7');
$driveProtectionUnitsArray []= $driveProtectionUnitsDriveProtectionUnit2;
$driveProtectionUnitsDriveProtectionUnit3 = new DriveProtectionUnit();
$driveProtectionUnitsDriveProtectionUnit3->setDirectoryObjectId('b218eb4a-ea72-42bd-8f0b-d0bbf794bec7');
$driveProtectionUnitsArray []= $driveProtectionUnitsDriveProtectionUnit3;
$requestBody->setDriveProtectionUnits($driveProtectionUnitsArray);
$result = $graphServiceClient->solutions()->backupRestore()->oneDriveForBusinessProtectionPolicies()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.BackupRestore
$params = @{
displayName = "OneDrive For Business Protection Policy"
driveProtectionUnits = @(
@{
directoryObjectId = "cdd3a849-dcaf-4a85-af82-7e39fc14019"
}
@{
directoryObjectId = "9bc069da-b746-41a4-89ab-26125c6373c7"
}
@{
directoryObjectId = "b218eb4a-ea72-42bd-8f0b-d0bbf794bec7"
}
)
}
New-MgBetaSolutionBackupRestoreOneDriveForBusinessProtectionPolicy -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.one_drive_for_business_protection_policy import OneDriveForBusinessProtectionPolicy
from msgraph_beta.generated.models.drive_protection_unit import DriveProtectionUnit
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = OneDriveForBusinessProtectionPolicy(
display_name = "OneDrive For Business Protection Policy",
drive_protection_units = [
DriveProtectionUnit(
directory_object_id = "cdd3a849-dcaf-4a85-af82-7e39fc14019",
),
DriveProtectionUnit(
directory_object_id = "9bc069da-b746-41a4-89ab-26125c6373c7",
),
DriveProtectionUnit(
directory_object_id = "b218eb4a-ea72-42bd-8f0b-d0bbf794bec7",
),
],
)
result = await graph_client.solutions.backup_restore.one_drive_for_business_protection_policies.post(request_body)
Réponse
L’exemple suivant illustre la réponse.
Remarque : l’objet de réponse affiché ci-après peut être raccourci pour plus de lisibilité.
HTTP/1.1 201 Created
Content-Location: https://graph.microsoft.com/beta/solutions/backupRestore/ProtectionPolicies/b218eb4a-ea72-42bd-8f0b-d0bbf794bec7
{
"@odata.context": "/solutions/backupRestore/$metadata#oneDriveForBusinessProtectionPolicies/$entity",
"id": "b218eb4a-ea72-42bd-8f0b-d0bbf794bec7",
"displayName": "OneDrive Protection Policy",
"status": "inactive",
"createdBy": {
"application": {
"id": "1fec8e78-bce4-4aaf-ab1b-5451cc387264",
"displayName": "Microsoft Enhanced Restore"
},
"user": {
"email": "User1@contoso.com",
"id": "845457dc-4bb2-4815-bef3-8628ebd1952e",
"displayName": "User1"
}
},
"createdDateTime": "2015-06-19T12:01:03.45Z",
"lastModifiedBy": {
"application": {
"id": "1fec8e78-bce4-4aaf-ab1b-5451cc387264",
"displayName": "Microsoft Enhanced Restore"
},
"user": {
"email": "User2@constoso.com",
"id": "845457dc-4bb2-4815-bef3-8628ebd1952e",
"displayName": "User2"
}
},
"lastModifiedDateTime": "2015-06-19T12:01:03.45Z",
"retentionSettings": [
{
"interval": "R/PT10M",
"period": "P2W"
},
{
"interval": "R/P1W",
"period": "P1Y"
}
]
}