Пространство имен: microsoft.graph
Важно!
API версии /beta
в Microsoft Graph могут быть изменены. Использование этих API в производственных приложениях не поддерживается. Чтобы определить, доступен ли API в версии 1.0, используйте селектор версий.
Используйте этот API для добавления вложения к существующему событию. Эта операция ограничивает размер вложения, в который можно добавить, до 3 МБ.
Если организатор добавляет вложение к событию собрания, организатор может впоследствии обновить событие, чтобы отправить вложение, а также обновить событие для каждого участника.
Этот API доступен в следующих национальных облачных развертываниях.
Глобальная служба |
Правительство США L4 |
Правительство США L5 (DOD) |
Китай управляется 21Vianet |
✅ |
✅ |
✅ |
✅ |
Разрешения
Выберите разрешение или разрешения, помеченные как наименее привилегированные для этого API. Используйте более привилегированное разрешение или разрешения только в том случае, если это требуется приложению. Дополнительные сведения о делегированных разрешениях и разрешениях приложений см. в разделе Типы разрешений. Дополнительные сведения об этих разрешениях см. в справочнике по разрешениям.
Тип разрешения |
Разрешения с наименьшими привилегиями |
Более высокие привилегированные разрешения |
Делегированные (рабочая или учебная учетная запись) |
Calendars.ReadWrite |
Недоступно. |
Делегированные (личная учетная запись Майкрософт) |
Calendars.ReadWrite |
Недоступно. |
Для приложений |
Calendars.ReadWrite |
Недоступно. |
HTTP-запрос
POST /me/events/{id}/attachments
POST /users/{id | userPrincipalName}/events/{id}/attachments
Имя |
Тип |
Описание |
Authorization |
string |
Bearer {token}. Обязательно. Дополнительные сведения о проверке подлинности и авторизации. |
Content-Type |
string |
Характер данных в теле объекта. Обязательно. |
Текст запроса
Предоставьте в тексте запроса описание объекта attachment в формате JSON.
Отклик
В случае успеха этот метод возвращает код отклика 201 Created
и объект attachment в тексте отклика.
Пример (вложенный файл)
Запрос
Ниже показан пример запроса.
POST https://graph.microsoft.com/beta/me/events/AAMkAGI1AAAt9AHjAAA=/attachments
Content-type: application/json
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "menu.txt",
"contentBytes": "bWFjIGFuZCBjaGVlc2UgdG9kYXk="
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new FileAttachment
{
OdataType = "#microsoft.graph.fileAttachment",
Name = "menu.txt",
ContentBytes = Convert.FromBase64String("bWFjIGFuZCBjaGVlc2UgdG9kYXk="),
};
// 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);
mgc-beta users events attachments create --user-id {user-id} --event-id {event-id} --body '{\
"@odata.type": "#microsoft.graph.fileAttachment",\
"name": "menu.txt",\
"contentBytes": "bWFjIGFuZCBjaGVlc2UgdG9kYXk="\
}\
'
// 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 := "menu.txt"
requestBody.SetName(&name)
contentBytes := []byte("bWFjIGFuZCBjaGVlc2UgdG9kYXk=")
requestBody.SetContentBytes(&contentBytes)
// 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);
FileAttachment attachment = new FileAttachment();
attachment.setOdataType("#microsoft.graph.fileAttachment");
attachment.setName("menu.txt");
byte[] contentBytes = Base64.getDecoder().decode("bWFjIGFuZCBjaGVlc2UgdG9kYXk=");
attachment.setContentBytes(contentBytes);
Attachment result = graphClient.me().events().byEventId("{event-id}").attachments().post(attachment);
const options = {
authProvider,
};
const client = Client.init(options);
const attachment = {
'@odata.type': '#microsoft.graph.fileAttachment',
name: 'menu.txt',
contentBytes: 'bWFjIGFuZCBjaGVlc2UgdG9kYXk='
};
await client.api('/me/events/AAMkAGI1AAAt9AHjAAA=/attachments')
.version('beta')
.post(attachment);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\FileAttachment;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new FileAttachment();
$requestBody->setOdataType('#microsoft.graph.fileAttachment');
$requestBody->setName('menu.txt');
$requestBody->setContentBytes(\GuzzleHttp\Psr7\Utils::streamFor(base64_decode('bWFjIGFuZCBjaGVlc2UgdG9kYXk=')));
$result = $graphServiceClient->me()->events()->byEventId('event-id')->attachments()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Calendar
$params = @{
"@odata.type" = "#microsoft.graph.fileAttachment"
name = "menu.txt"
contentBytes = "bWFjIGFuZCBjaGVlc2UgdG9kYXk="
}
# 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.file_attachment import FileAttachment
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = FileAttachment(
odata_type = "#microsoft.graph.fileAttachment",
name = "menu.txt",
content_bytes = base64.urlsafe_b64decode("bWFjIGFuZCBjaGVlc2UgdG9kYXk="),
)
result = await graph_client.me.events.by_event_id('event-id').attachments.post(request_body)
Предоставьте в тексте запроса описание объекта attachment в формате JSON.
Отклик
Ниже показан пример отклика. Примечание. Объект отклика, показанный здесь, может быть сокращен для удобочитаемости.
HTTP 201 Created
Content-Length: 735
{
"@odata.context":"https://graph.microsoft.com/beta/$metadata#users('cd209b0b-3f83-4c35-82d2-d88a61820480')/events('AAMkAGI1AAAt9AHjAAA%3D')/attachments/$entity",
"@odata.type":"#microsoft.graph.fileAttachment",
"id":"AAMkAGI1AAAt9AHjAAABEgAQAEdBogju-MJEu6Ngg-1_W0g=",
"lastModifiedDateTime":"2017-04-15T03:21:49Z",
"name":"menu.txt",
"contentType":"text/plain",
"size":178,
"isInline":false,
"contentId":null,
"contentLocation":null,
"contentBytes":"bWFjIGFuZCBjaGVlc2UgdG9kYXk="
}
Пример (вложенный элемент)
Запрос
Ниже приведен пример, в котором событие присоединяется к другому событию в виде вложения элемента.
POST https://graph.microsoft.com/beta/me/events/AAMkAGI1AAAt9AHjAAA=/attachments
Content-type: application/json
{
"@odata.type": "#microsoft.graph.itemAttachment",
"name": "Holiday event",
"item": {
"@odata.type": "microsoft.graph.event",
"subject": "Discuss gifts for children",
"body": {
"contentType": "HTML",
"content": "Let's look for funding!"
},
"start": {
"dateTime": "2016-12-02T18:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2016-12-02T19:00:00",
"timeZone": "Pacific Standard Time"
}
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new ItemAttachment
{
OdataType = "#microsoft.graph.itemAttachment",
Name = "Holiday event",
Item = new Event
{
OdataType = "microsoft.graph.event",
Subject = "Discuss gifts for children",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Let's look for funding!",
},
Start = new DateTimeTimeZone
{
DateTime = "2016-12-02T18:00:00",
TimeZone = "Pacific Standard Time",
},
End = new DateTimeTimeZone
{
DateTime = "2016-12-02T19:00:00",
TimeZone = "Pacific Standard Time",
},
},
};
// 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);
mgc-beta users events attachments create --user-id {user-id} --event-id {event-id} --body '{\
"@odata.type": "#microsoft.graph.itemAttachment",\
"name": "Holiday event",\
"item": {\
"@odata.type": "microsoft.graph.event",\
"subject": "Discuss gifts for children",\
"body": {\
"contentType": "HTML",\
"content": "Let's look for funding!"\
},\
"start": {\
"dateTime": "2016-12-02T18:00:00",\
"timeZone": "Pacific Standard Time"\
},\
"end": {\
"dateTime": "2016-12-02T19:00:00",\
"timeZone": "Pacific Standard Time"\
}\
}\
}\
'
// 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 := "Holiday event"
requestBody.SetName(&name)
item := graphmodels.NewEvent()
subject := "Discuss gifts for children"
item.SetSubject(&subject)
body := graphmodels.NewItemBody()
contentType := graphmodels.HTML_BODYTYPE
body.SetContentType(&contentType)
content := "Let's look for funding!"
body.SetContent(&content)
item.SetBody(body)
start := graphmodels.NewDateTimeTimeZone()
dateTime := "2016-12-02T18:00:00"
start.SetDateTime(&dateTime)
timeZone := "Pacific Standard Time"
start.SetTimeZone(&timeZone)
item.SetStart(start)
end := graphmodels.NewDateTimeTimeZone()
dateTime := "2016-12-02T19:00:00"
end.SetDateTime(&dateTime)
timeZone := "Pacific Standard Time"
end.SetTimeZone(&timeZone)
item.SetEnd(end)
requestBody.SetItem(item)
// 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);
ItemAttachment attachment = new ItemAttachment();
attachment.setOdataType("#microsoft.graph.itemAttachment");
attachment.setName("Holiday event");
Event item = new Event();
item.setOdataType("microsoft.graph.event");
item.setSubject("Discuss gifts for children");
ItemBody body = new ItemBody();
body.setContentType(BodyType.Html);
body.setContent("Let's look for funding!");
item.setBody(body);
DateTimeTimeZone start = new DateTimeTimeZone();
start.setDateTime("2016-12-02T18:00:00");
start.setTimeZone("Pacific Standard Time");
item.setStart(start);
DateTimeTimeZone end = new DateTimeTimeZone();
end.setDateTime("2016-12-02T19:00:00");
end.setTimeZone("Pacific Standard Time");
item.setEnd(end);
attachment.setItem(item);
Attachment result = graphClient.me().events().byEventId("{event-id}").attachments().post(attachment);
const options = {
authProvider,
};
const client = Client.init(options);
const attachment = {
'@odata.type': '#microsoft.graph.itemAttachment',
name: 'Holiday event',
item: {
'@odata.type': 'microsoft.graph.event',
subject: 'Discuss gifts for children',
body: {
contentType: 'HTML',
content: 'Let\'s look for funding!'
},
start: {
dateTime: '2016-12-02T18:00:00',
timeZone: 'Pacific Standard Time'
},
end: {
dateTime: '2016-12-02T19:00:00',
timeZone: 'Pacific Standard Time'
}
}
};
await client.api('/me/events/AAMkAGI1AAAt9AHjAAA=/attachments')
.version('beta')
.post(attachment);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\ItemAttachment;
use Microsoft\Graph\Beta\Generated\Models\Event;
use Microsoft\Graph\Beta\Generated\Models\ItemBody;
use Microsoft\Graph\Beta\Generated\Models\BodyType;
use Microsoft\Graph\Beta\Generated\Models\DateTimeTimeZone;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new ItemAttachment();
$requestBody->setOdataType('#microsoft.graph.itemAttachment');
$requestBody->setName('Holiday event');
$item = new Event();
$item->setOdataType('microsoft.graph.event');
$item->setSubject('Discuss gifts for children');
$itemBody = new ItemBody();
$itemBody->setContentType(new BodyType('hTML'));
$itemBody->setContent('Let\'s look for funding!');
$item->setBody($itemBody);
$itemStart = new DateTimeTimeZone();
$itemStart->setDateTime('2016-12-02T18:00:00');
$itemStart->setTimeZone('Pacific Standard Time');
$item->setStart($itemStart);
$itemEnd = new DateTimeTimeZone();
$itemEnd->setDateTime('2016-12-02T19:00:00');
$itemEnd->setTimeZone('Pacific Standard Time');
$item->setEnd($itemEnd);
$requestBody->setItem($item);
$result = $graphServiceClient->me()->events()->byEventId('event-id')->attachments()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Calendar
$params = @{
"@odata.type" = "#microsoft.graph.itemAttachment"
name = "Holiday event"
item = @{
"@odata.type" = "microsoft.graph.event"
subject = "Discuss gifts for children"
body = @{
contentType = "HTML"
content = "Let's look for funding!"
}
start = @{
dateTime = "2016-12-02T18:00:00"
timeZone = "Pacific Standard Time"
}
end = @{
dateTime = "2016-12-02T19:00:00"
timeZone = "Pacific Standard Time"
}
}
}
# 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.item_attachment import ItemAttachment
from msgraph_beta.generated.models.event import Event
from msgraph_beta.generated.models.item_body import ItemBody
from msgraph_beta.generated.models.body_type import BodyType
from msgraph_beta.generated.models.date_time_time_zone import DateTimeTimeZone
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = ItemAttachment(
odata_type = "#microsoft.graph.itemAttachment",
name = "Holiday event",
item = Event(
odata_type = "microsoft.graph.event",
subject = "Discuss gifts for children",
body = ItemBody(
content_type = BodyType.Html,
content = "Let's look for funding!",
),
start = DateTimeTimeZone(
date_time = "2016-12-02T18:00:00",
time_zone = "Pacific Standard Time",
),
end = DateTimeTimeZone(
date_time = "2016-12-02T19:00:00",
time_zone = "Pacific Standard Time",
),
),
)
result = await graph_client.me.events.by_event_id('event-id').attachments.post(request_body)
Отклик
Ниже показан пример отклика. Примечание. Объект отклика, показанный здесь, может быть сокращен для удобочитаемости.
HTTP 201 Created
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/beta/$metadata#me/events('AAMkAGI1AAAt9AHjAAA=')/attachments/$entity",
"@odata.type":"#microsoft.graph.itemAttachment",
"@odata.id":"https://graph.microsoft.com/beta/users('fdcbcf34-2505-4d07-be5b-0a55b699d157@41a5b830-45ac-4f1b-9bfc-baafa3b7db2e')/events('AAMkAGI1AAAt9AHjAAA=')/attachments('AAMkADNkN2Jp5JVnQIe9r0=')",
"id":"AAMkADNkNJp5JVnQIe9r0=",
"lastModifiedDateTime":"2016-12-01T22:27:13Z",
"name":"Holiday event",
"contentType":null,
"size":2473,
"isInline":false
}
Пример (вложенная ссылка)
Запрос
В следующем примере показан запрос, который добавляет вложение ссылки к существующему событию.
Вложение указывает на папку в OneDrive.
POST https://graph.microsoft.com/beta/me/events/AAMkAGE1M88AADUv0uAAAG=/attachments
Content-type: application/json
{
"@odata.type": "#microsoft.graph.referenceAttachment",
"name": "Personal pictures",
"sourceUrl": "https://contoso.com/personal/mario_contoso_net/Documents/Pics",
"providerType": "oneDriveConsumer",
"permission": "Edit",
"isFolder": "True"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new ReferenceAttachment
{
OdataType = "#microsoft.graph.referenceAttachment",
Name = "Personal pictures",
SourceUrl = "https://contoso.com/personal/mario_contoso_net/Documents/Pics",
ProviderType = ReferenceAttachmentProvider.OneDriveConsumer,
Permission = ReferenceAttachmentPermission.Edit,
IsFolder = true,
};
// 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);
mgc-beta users events attachments create --user-id {user-id} --event-id {event-id} --body '{\
"@odata.type": "#microsoft.graph.referenceAttachment",\
"name": "Personal pictures",\
"sourceUrl": "https://contoso.com/personal/mario_contoso_net/Documents/Pics",\
"providerType": "oneDriveConsumer",\
"permission": "Edit",\
"isFolder": "True"\
}\
'
// 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 := "Personal pictures"
requestBody.SetName(&name)
sourceUrl := "https://contoso.com/personal/mario_contoso_net/Documents/Pics"
requestBody.SetSourceUrl(&sourceUrl)
providerType := graphmodels.ONEDRIVECONSUMER_REFERENCEATTACHMENTPROVIDER
requestBody.SetProviderType(&providerType)
permission := graphmodels.EDIT_REFERENCEATTACHMENTPERMISSION
requestBody.SetPermission(&permission)
isFolder := true
requestBody.SetIsFolder(&isFolder)
// 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);
ReferenceAttachment attachment = new ReferenceAttachment();
attachment.setOdataType("#microsoft.graph.referenceAttachment");
attachment.setName("Personal pictures");
attachment.setSourceUrl("https://contoso.com/personal/mario_contoso_net/Documents/Pics");
attachment.setProviderType(ReferenceAttachmentProvider.OneDriveConsumer);
attachment.setPermission(ReferenceAttachmentPermission.Edit);
attachment.setIsFolder(true);
Attachment result = graphClient.me().events().byEventId("{event-id}").attachments().post(attachment);
const options = {
authProvider,
};
const client = Client.init(options);
const attachment = {
'@odata.type': '#microsoft.graph.referenceAttachment',
name: 'Personal pictures',
sourceUrl: 'https://contoso.com/personal/mario_contoso_net/Documents/Pics',
providerType: 'oneDriveConsumer',
permission: 'Edit',
isFolder: 'True'
};
await client.api('/me/events/AAMkAGE1M88AADUv0uAAAG=/attachments')
.version('beta')
.post(attachment);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\ReferenceAttachment;
use Microsoft\Graph\Beta\Generated\Models\ReferenceAttachmentProvider;
use Microsoft\Graph\Beta\Generated\Models\ReferenceAttachmentPermission;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new ReferenceAttachment();
$requestBody->setOdataType('#microsoft.graph.referenceAttachment');
$requestBody->setName('Personal pictures');
$requestBody->setSourceUrl('https://contoso.com/personal/mario_contoso_net/Documents/Pics');
$requestBody->setProviderType(new ReferenceAttachmentProvider('oneDriveConsumer'));
$requestBody->setPermission(new ReferenceAttachmentPermission('edit'));
$requestBody->setIsFolder(true);
$result = $graphServiceClient->me()->events()->byEventId('event-id')->attachments()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Calendar
$params = @{
"@odata.type" = "#microsoft.graph.referenceAttachment"
name = "Personal pictures"
sourceUrl = "https://contoso.com/personal/mario_contoso_net/Documents/Pics"
providerType = "oneDriveConsumer"
permission = "Edit"
isFolder = "True"
}
# 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.reference_attachment import ReferenceAttachment
from msgraph_beta.generated.models.reference_attachment_provider import ReferenceAttachmentProvider
from msgraph_beta.generated.models.reference_attachment_permission import ReferenceAttachmentPermission
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = ReferenceAttachment(
odata_type = "#microsoft.graph.referenceAttachment",
name = "Personal pictures",
source_url = "https://contoso.com/personal/mario_contoso_net/Documents/Pics",
provider_type = ReferenceAttachmentProvider.OneDriveConsumer,
permission = ReferenceAttachmentPermission.Edit,
is_folder = True,
)
result = await graph_client.me.events.by_event_id('event-id').attachments.post(request_body)
Отклик
Ниже приведен пример полного ответа.
HTTP 201 Created
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#users/ddfcd489-628b-40d7-b48b-57002df800e5/events/AAMkAGE1M88AADUv0uAAAG%3D/attachments/$entity",
"@odata.type": "#microsoft.graph.referenceAttachment",
"id": "AAMkAGE1Mg72tgf7hJp0PCGVCIc0g=",
"lastModifiedDateTime": "2016-03-12T06:04:38Z",
"name": "Personal pictures",
"contentType": null,
"size": 382,
"isInline": false,
"sourceUrl": "https://contoso.com/personal/mario_contoso_net/Documents/Pics",
"providerType": "oneDriveConsumer",
"thumbnailUrl": null,
"previewUrl": null,
"permission": "edit",
"isFolder": true
}