添付ファイルを追加するAdd attachment

添付ファイルをイベントに追加する場合に、この API を使用します。現在、各 REST 要求の合計サイズは 4 MB に制限されているため、追加できる添付ファイルのサイズは 4 MB 未満に制限されます。Use this API to add an attachment to an event. Since there is currently a limit of 4MB on the total size of each REST request, this limits the size of the attachment you can add to under 4MB.

アクセス許可Permissions

この API を呼び出すには、次のいずれかのアクセス許可が必要です。アクセス許可の選択方法などの詳細については、「アクセス許可」を参照してください。One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.

アクセス許可の種類Permission type アクセス許可 (特権の小さいものから大きいものへ)Permissions (from least to most privileged)
委任 (職場または学校のアカウント)Delegated (work or school account) Calendars.ReadWriteCalendars.ReadWrite
委任 (個人用 Microsoft アカウント)Delegated (personal Microsoft account) Calendars.ReadWriteCalendars.ReadWrite
アプリケーションApplication Calendars.ReadWriteCalendars.ReadWrite

HTTP 要求HTTP request

ユーザーの既定の予定表にあるイベントの添付ファイル。Attachments for an event in the user's default calendar.

POST /me/events/{id}/attachments
POST /users/{id | userPrincipalName}/events/{id}/attachments

POST /me/calendar/events/{id}/attachments
POST /users/{id | userPrincipalName}/calendar/events/{id}/attachments

ユーザーの既定 calendarGroup に属するカレンダーイベントの添付ファイル。Attachments for an event in a calendar belonging to the user's default calendarGroup.

POST /me/calendars/{id}/events/{id}/attachments
POST /users/{id | userPrincipalName}/calendars/{id}/events/{id}/attachments

POST /me/calendargroup/calendars/{id}/events/{id}/attachments
POST /users/{id | userPrincipalName}/calendargroup/calendars/{id}/events/{id}/attachments

ユーザーの calendarGroup に属するカレンダーイベントの添付ファイル。Attachments for an event in a calendar belonging to a user's calendarGroup.

POST /me/calendargroups/{id}/calendars/{id}/events/{id}/attachments
POST /users/{id | userPrincipalName}/calendargroups/{id}/calendars/{id}/events/{id}/attachments

要求ヘッダーRequest headers

名前Name Type 説明Description
AuthorizationAuthorization stringstring ベアラー {トークン}。必須。Bearer {token}. Required.
Content-TypeContent-Type stringstring エンティティ本文内のデータの性質です。必須。Nature of the data in the body of an entity. Required.

要求本文Request body

要求本文で、attachment オブジェクトの JSON 表記を指定します。In the request body, supply a JSON representation of attachment object.

応答Response

成功した場合、このメソッドは 201 Created 応答コードと、応答本文で attachment オブジェクトを返します。If successful, this method returns 201 Created response code and attachment object in the response body.

例 (添付ファイル)Example (file attachment)

要求Request

以下は、要求の例です。Here is an example of the request.

POST https://graph.microsoft.com/v1.0/me/events/AAMkAGI1AAAt9AHjAAA=/attachments
Content-type: application/json
Content-length: 151

{
    "@odata.type": "#microsoft.graph.fileAttachment",
    "name": "menu.txt",
    "contentBytes": "base64bWFjIGFuZCBjaGVlc2UgdG9kYXk="   
}

要求本文で、Attachment オブジェクトの JSON 表記を指定します。In the request body, supply a JSON representation of attachment object.

応答Response

以下は、応答の例です。Here is an example of the response.

HTTP 201 Created
Content-type: application/json

{
    "@odata.context":"https://graph.microsoft.com/v1.0/$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":"base64bWFjIGFuZCBjaGVlc2UgdG9kYXk="
}

SDK サンプルコードSDK sample code


const options = {
    authProvider,
};

const client = Client.init(options);

const attachment = {
    @odata.type: "#microsoft.graph.fileAttachment",
    name: "menu.txt",
    contentBytes: "base64bWFjIGFuZCBjaGVlc2UgdG9kYXk="   
};

let res = await client.api('/me/events/AAMkAGI1AAAt9AHjAAA=/attachments')
    .post({attachment : attachment});

SDK をプロジェクトに追加し、 authproviderインスタンスを作成する方法の詳細については、 sdk のドキュメントを参照してください。Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.

例 (項目の添付ファイル)Example (item attachment)

要求Request

以下は、アイテムの添付ファイルとしてイベントを別のイベントに添付する例です。Here is an example which attaches an event with another event as an item attachment.

POST https://graph.microsoft.com/v1.0/me/events/AAMkAGI1AAAt9AHjAAA=/attachments
Content-type: application/json
Content-length: 600

{
  "@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"
          }
    }
}
応答Response

以下は、応答の例です。Here is an example of the response.

HTTP 201 Created
Content-type: application/json
Content-length: 162

{
    "@odata.context":"https://graph.microsoft.com/v1.0/$metadata#me/events('AAMkAGI1AAAt9AHjAAA=')/attachments/$entity",
    "@odata.type":"#microsoft.graph.itemAttachment",
    "@odata.id":"https://graph.microsoft.com/v1.0/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
}

SDK サンプルコードSDK sample code


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"
          }
    }
};

let res = await client.api('/me/events/AAMkAGI1AAAt9AHjAAA=/attachments')
    .post({attachment : attachment});

SDK をプロジェクトに追加し、 authproviderインスタンスを作成する方法の詳細については、 sdk のドキュメントを参照してください。Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.