Namespace: microsoft.graph
Wichtig
Die APIs unter der /beta Version in Microsoft Graph können sich ändern. Die Verwendung dieser APIs in Produktionsanwendungen wird nicht unterstützt. Um festzustellen, ob eine API in v1.0 verfügbar ist, verwenden Sie die Version Selektor.
Verwenden Sie diese API, um eine neue Anlage zu erstellen.
Eine Anlage weist einen der folgenden Typen auf:
All diese Typen von Anlagenressourcen werden von der Ressource attachment abgeleitet.
Diese API ist in den folgenden nationalen Cloudbereitstellungen verfügbar.
| Weltweiter Service |
US Government L4 |
US Government L5 (DOD) |
China, betrieben von 21Vianet |
| ✅ |
✅ |
✅ |
✅ |
Berechtigungen
Wählen Sie die Berechtigungen aus, die für diese API als am wenigsten privilegiert markiert sind. Verwenden Sie eine höhere Berechtigung oder Berechtigungen nur, wenn Ihre App dies erfordert. Ausführliche Informationen zu delegierten Berechtigungen und Anwendungsberechtigungen finden Sie unter Berechtigungstypen. Weitere Informationen zu diesen Berechtigungen finden Sie in der Berechtigungsreferenz.
| Berechtigungstyp |
Berechtigungen mit den geringsten Berechtigungen |
Berechtigungen mit höheren Berechtigungen |
| Delegiert (Geschäfts-, Schul- oder Unikonto) |
Mail.ReadWrite |
Nicht verfügbar. |
| Delegiert (persönliches Microsoft-Konto) |
Mail.ReadWrite |
Nicht verfügbar. |
| Anwendung |
Mail.ReadWrite |
Nicht verfügbar. |
HTTP-Anforderung
POST /me/messages/{id}/attachments
POST /users/{id|userPrincipalName}/messages/{id}/attachments
| Name |
Typ |
Beschreibung |
| Authorization |
string |
Bearer {token}. Erforderlich. Erfahren Sie mehr über Authentifizierung und Autorisierung. |
| Content-Type |
string |
Die Art der Daten im Textkörper einer Entität. Erforderlich. |
Anforderungstext
Geben Sie im Anforderungstext eine JSON-Darstellung des Attachment-Objekts an.
Antwort
Wenn die Methode erfolgreich verläuft, werden der Antwortcode 201 Created und ein Attachment-Objekt im Antworttext zurückgegeben.
Beispiel (Dateianlage)
Anforderung
Das folgende Beispiel zeigt eine Anfrage.
POST https://graph.microsoft.com/beta/me/messages/{id}/attachments
Content-type: application/json
{
"@odata.type": "#Microsoft.OutlookServices.FileAttachment",
"name": "name-value",
"contentType": "contentType-value",
"isInline": false,
"contentLocation": "contentLocation-value",
"contentBytes": "contentBytes-value"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Attachment
{
OdataType = "#Microsoft.OutlookServices.FileAttachment",
Name = "name-value",
ContentType = "contentType-value",
IsInline = false,
AdditionalData = new Dictionary<string, object>
{
{
"contentLocation" , "contentLocation-value"
},
{
"contentBytes" , "contentBytes-value"
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.Messages["{message-id}"].Attachments.PostAsync(requestBody);
// 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.NewAttachment()
name := "name-value"
requestBody.SetName(&name)
contentType := "contentType-value"
requestBody.SetContentType(&contentType)
isInline := false
requestBody.SetIsInline(&isInline)
additionalData := map[string]interface{}{
"contentLocation" : "contentLocation-value",
"contentBytes" : "contentBytes-value",
}
requestBody.SetAdditionalData(additionalData)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
attachments, err := graphClient.Me().Messages().ByMessageId("message-id").Attachments().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Attachment attachment = new Attachment();
attachment.setOdataType("#Microsoft.OutlookServices.FileAttachment");
attachment.setName("name-value");
attachment.setContentType("contentType-value");
attachment.setIsInline(false);
HashMap<String, Object> additionalData = new HashMap<String, Object>();
additionalData.put("contentLocation", "contentLocation-value");
additionalData.put("contentBytes", "contentBytes-value");
attachment.setAdditionalData(additionalData);
Attachment result = graphClient.me().messages().byMessageId("{message-id}").attachments().post(attachment);
const options = {
authProvider,
};
const client = Client.init(options);
const attachment = {
'@odata.type': '#Microsoft.OutlookServices.FileAttachment',
name: 'name-value',
contentType: 'contentType-value',
isInline: false,
contentLocation: 'contentLocation-value',
contentBytes: 'contentBytes-value'
};
await client.api('/me/messages/{id}/attachments')
.version('beta')
.post(attachment);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Attachment;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Attachment();
$requestBody->setOdataType('#Microsoft.OutlookServices.FileAttachment');
$requestBody->setName('name-value');
$requestBody->setContentType('contentType-value');
$requestBody->setIsInline(false);
$additionalData = [
'contentLocation' => 'contentLocation-value',
'contentBytes' => 'contentBytes-value',
];
$requestBody->setAdditionalData($additionalData);
$result = $graphServiceClient->me()->messages()->byMessageId('message-id')->attachments()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Mail
$params = @{
"@odata.type" = "#Microsoft.OutlookServices.FileAttachment"
name = "name-value"
contentType = "contentType-value"
isInline = $false
contentLocation = "contentLocation-value"
contentBytes = "contentBytes-value"
}
# A UPN can also be used as -UserId.
New-MgBetaUserMessageAttachment -UserId $userId -MessageId $messageId -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.attachment import Attachment
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Attachment(
odata_type = "#Microsoft.OutlookServices.FileAttachment",
name = "name-value",
content_type = "contentType-value",
is_inline = False,
additional_data = {
"content_location" : "contentLocation-value",
"content_bytes" : "contentBytes-value",
}
)
result = await graph_client.me.messages.by_message_id('message-id').attachments.post(request_body)
Antwort
Das folgende Beispiel zeigt die Antwort. Hinweis: Das hier gezeigte Antwortobjekt kann zur besseren Lesbarkeit gekürzt sein.
HTTP 201 Created
Beispiel (Elementanlage)
Anforderung
POST https://graph.microsoft.com/beta/me/events/{id}/attachments
Content-type: application/json
{
"@odata.type": "#Microsoft.OutlookServices.ItemAttachment",
"name": "name-value",
"item": {
"@odata.type": "microsoft.graph.message"
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Attachment
{
OdataType = "#Microsoft.OutlookServices.ItemAttachment",
Name = "name-value",
AdditionalData = new Dictionary<string, object>
{
{
"item" , new Message
{
OdataType = "microsoft.graph.message",
}
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.Events["{event-id}"].Attachments.PostAsync(requestBody);
// 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.NewAttachment()
name := "name-value"
requestBody.SetName(&name)
additionalData := map[string]interface{}{
item := graphmodels.NewMessage()
requestBody.SetItem(item)
}
requestBody.SetAdditionalData(additionalData)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
attachments, err := graphClient.Me().Events().ByEventId("event-id").Attachments().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Attachment attachment = new Attachment();
attachment.setOdataType("#Microsoft.OutlookServices.ItemAttachment");
attachment.setName("name-value");
HashMap<String, Object> additionalData = new HashMap<String, Object>();
Message item = new Message();
item.setOdataType("microsoft.graph.message");
additionalData.put("item", item);
attachment.setAdditionalData(additionalData);
Attachment result = graphClient.me().events().byEventId("{event-id}").attachments().post(attachment);
const options = {
authProvider,
};
const client = Client.init(options);
const attachment = {
'@odata.type': '#Microsoft.OutlookServices.ItemAttachment',
name: 'name-value',
item: {
'@odata.type': 'microsoft.graph.message'
}
};
await client.api('/me/events/{id}/attachments')
.version('beta')
.post(attachment);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Attachment;
use Microsoft\Graph\Beta\Generated\Models\Message;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Attachment();
$requestBody->setOdataType('#Microsoft.OutlookServices.ItemAttachment');
$requestBody->setName('name-value');
$additionalData = [
'item' => [
'@odata.type' => 'microsoft.graph.message',
],
];
$requestBody->setAdditionalData($additionalData);
$result = $graphServiceClient->me()->events()->byEventId('event-id')->attachments()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Calendar
$params = @{
"@odata.type" = "#Microsoft.OutlookServices.ItemAttachment"
name = "name-value"
item = @{
"@odata.type" = "microsoft.graph.message"
}
}
# A UPN can also be used as -UserId.
New-MgBetaUserEventAttachment -UserId $userId -EventId $eventId -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.attachment import Attachment
from msgraph_beta.generated.models.message import Message
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Attachment(
odata_type = "#Microsoft.OutlookServices.ItemAttachment",
name = "name-value",
additional_data = {
"item" : {
"@odata_type" : "microsoft.graph.message",
},
}
)
result = await graph_client.me.events.by_event_id('event-id').attachments.post(request_body)
Antwort
Das folgende Beispiel zeigt die Antwort. Hinweis: Das hier gezeigte Antwortobjekt kann zur besseren Lesbarkeit gekürzt sein.
HTTP 201 Created