Wählen Sie für diese API die Als am wenigsten privilegierten Berechtigungen gekennzeichneten Berechtigungen aus. Verwenden Sie nur dann eine Berechtigung mit höheren Berechtigungen , wenn dies für Ihre App erforderlich ist. Ausführliche Informationen zu delegierten Berechtigungen und Anwendungsberechtigungen finden Sie unter Berechtigungstypen. Weitere Informationen zu diesen Berechtigungen finden Sie in der Berechtigungsreferenz.
Geben Sie im Anforderungstext eine JSON-Darstellung des zu erstellenden Bündels an.
Antwort
Wenn die Anforderung erfolgreich ist, wird das driveItem-Objekt zurückgegeben, das das neu erstellte Bündel darstellt.
Informationen zu Fehlerantworten finden Sie unter Fehlerantworten.
Beispiele
Beispiel 1: Erstellen eines Pakets
Das folgende Beispiel zeigt, wie Sie ein einfaches neues Bündel erstellen.
Diese Anforderung erstellt ein neues Bündel mit dem Namen Just some files und fügt dem Bündel zwei vorhandene Elemente hinzu.
Dieses Bündel kann verwendet werden, um eine Sammlung von Dateien für andere Benutzer freizugeben, ohne den Ordner freizugeben, in dem diese Elemente gespeichert sind.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new DriveItem
{
Name = "Just some files",
Bundle = new Bundle
{
},
Children = new List<DriveItem>
{
new DriveItem
{
Id = "1234asdf",
},
new DriveItem
{
Id = "1234qwerty",
},
},
AdditionalData = new Dictionary<string, object>
{
{
"@microsoft.graph.conflictBehavior" , "rename"
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Drives["{drive-id}"].Bundles.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewDriveItem()
name := "Just some files"
requestBody.SetName(&name)
bundle := graphmodels.NewBundle()
requestBody.SetBundle(bundle)
driveItem := graphmodels.NewDriveItem()
id := "1234asdf"
driveItem.SetId(&id)
driveItem1 := graphmodels.NewDriveItem()
id := "1234qwerty"
driveItem1.SetId(&id)
children := []graphmodels.DriveItemable {
driveItem,
driveItem1,
}
requestBody.SetChildren(children)
additionalData := map[string]interface{}{
"@microsoft.graph.conflictBehavior" : "rename",
}
requestBody.SetAdditionalData(additionalData)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
bundles, err := graphClient.Drives().ByDriveId("drive-id").Bundles().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
DriveItem driveItem = new DriveItem();
driveItem.setName("Just some files");
Bundle bundle = new Bundle();
driveItem.setBundle(bundle);
LinkedList<DriveItem> children = new LinkedList<DriveItem>();
DriveItem driveItem1 = new DriveItem();
driveItem1.setId("1234asdf");
children.add(driveItem1);
DriveItem driveItem2 = new DriveItem();
driveItem2.setId("1234qwerty");
children.add(driveItem2);
driveItem.setChildren(children);
HashMap<String, Object> additionalData = new HashMap<String, Object>();
additionalData.put("@microsoft.graph.conflictBehavior", "rename");
driveItem.setAdditionalData(additionalData);
DriveItem result = graphClient.drives().byDriveId("{drive-id}").bundles().post(driveItem);
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.drive_item import DriveItem
from msgraph.generated.models.bundle import Bundle
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = DriveItem(
name = "Just some files",
bundle = Bundle(
),
children = [
DriveItem(
id = "1234asdf",
),
DriveItem(
id = "1234qwerty",
),
],
additional_data = {
"@microsoft_graph_conflict_behavior" : "rename",
}
)
result = await graph_client.drives.by_drive_id('drive-id').bundles.post(request_body)
HTTP/1.1 201 Created
Content-Type: application/json
{
"id": "1234321!abc",
"name": "Just some files",
"bundle": {
"childCount": 2
}
}
Das hier gezeigte Antwortobjekt wird möglicherweise zur besseren Lesbarkeit verkürzt.
Beispiel 2: Erstellen eines Albums
Die Anforderung zum Erstellen eines neuen Fotoalbums ist ähnlich, obwohl die Albumeigenschaft innerhalb des Bündelfacets auf einen Wert ungleich NULL festgelegt ist.
POST https://graph.microsoft.com/v1.0/drive/bundles
Content-Type: application/json
{
"name": "My Day at the Beach",
"@microsoft.graph.conflictBehavior" : "rename",
"bundle": { "album": {} },
"children": [
{ "id": "1234asdf" }
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new DriveItem
{
Name = "My Day at the Beach",
Bundle = new Bundle
{
Album = new Album
{
},
},
Children = new List<DriveItem>
{
new DriveItem
{
Id = "1234asdf",
},
},
AdditionalData = new Dictionary<string, object>
{
{
"@microsoft.graph.conflictBehavior" , "rename"
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Drives["{drive-id}"].Bundles.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewDriveItem()
name := "My Day at the Beach"
requestBody.SetName(&name)
bundle := graphmodels.NewBundle()
album := graphmodels.NewAlbum()
bundle.SetAlbum(album)
requestBody.SetBundle(bundle)
driveItem := graphmodels.NewDriveItem()
id := "1234asdf"
driveItem.SetId(&id)
children := []graphmodels.DriveItemable {
driveItem,
}
requestBody.SetChildren(children)
additionalData := map[string]interface{}{
"@microsoft.graph.conflictBehavior" : "rename",
}
requestBody.SetAdditionalData(additionalData)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
bundles, err := graphClient.Drives().ByDriveId("drive-id").Bundles().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
DriveItem driveItem = new DriveItem();
driveItem.setName("My Day at the Beach");
Bundle bundle = new Bundle();
Album album = new Album();
bundle.setAlbum(album);
driveItem.setBundle(bundle);
LinkedList<DriveItem> children = new LinkedList<DriveItem>();
DriveItem driveItem1 = new DriveItem();
driveItem1.setId("1234asdf");
children.add(driveItem1);
driveItem.setChildren(children);
HashMap<String, Object> additionalData = new HashMap<String, Object>();
additionalData.put("@microsoft.graph.conflictBehavior", "rename");
driveItem.setAdditionalData(additionalData);
DriveItem result = graphClient.drives().byDriveId("{drive-id}").bundles().post(driveItem);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\DriveItem;
use Microsoft\Graph\Generated\Models\Bundle;
use Microsoft\Graph\Generated\Models\Album;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new DriveItem();
$requestBody->setName('My Day at the Beach');
$bundle = new Bundle();
$bundleAlbum = new Album();
$bundle->setAlbum($bundleAlbum);
$requestBody->setBundle($bundle);
$childrenDriveItem1 = new DriveItem();
$childrenDriveItem1->setId('1234asdf');
$childrenArray []= $childrenDriveItem1;
$requestBody->setChildren($childrenArray);
$additionalData = [
'@microsoft.graph.conflictBehavior' => 'rename',
];
$requestBody->setAdditionalData($additionalData);
$result = $graphServiceClient->drives()->byDriveId('drive-id')->bundles()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Files
$params = @{
name = "My Day at the Beach"
"@microsoft.graph.conflictBehavior" = "rename"
bundle = @{
album = @{
}
}
children = @(
@{
id = "1234asdf"
}
)
}
New-MgDriveBundle -DriveId $driveId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.drive_item import DriveItem
from msgraph.generated.models.bundle import Bundle
from msgraph.generated.models.album import Album
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = DriveItem(
name = "My Day at the Beach",
bundle = Bundle(
album = Album(
),
),
children = [
DriveItem(
id = "1234asdf",
),
],
additional_data = {
"@microsoft_graph_conflict_behavior" : "rename",
}
)
result = await graph_client.drives.by_drive_id('drive-id').bundles.post(request_body)
Das hier gezeigte Antwortobjekt wird möglicherweise zur besseren Lesbarkeit verkürzt.
Wenn @microsoft.graph.conflictBehavior auf umbenennen festgelegt ist und bereits ein Bündel mit demselben Namen vorhanden ist, wird der name des neuen Bündels so aktualisiert, dass er eindeutig ist.
OneDrive fügt eine Zahl an das Ende des Bundlenamens an.
My Day at the Beach beispielsweise würde umbenannt in My Day at the Beach 1.
Wenn My Day at the Beach 1 verwendet wird, wird die Zahl erneut erhöht, bis ein eindeutiger Bündelname gefunden wird.