如何从Office 365 Mail REST API中的ItemAttachment检索FileAttachment?

时间:2015-10-20 14:20:08

标签: api rest email office365

有关更多背景信息,请参阅this thread。在弄清楚如何通过Office 365 Mail REST API从消息中检索ItemAttachments后,我现在遇到另一个问题:从ItemAttachments中检索FileAttachments。

API指南不包含此内容(据我所知)。当我检索ItemAttachment时,“HasAttachment”键的值为“true”,但我无法弄清楚如何检索它。

我(盲目地)尝试了以下URI:

/api/v1.0/me/messages/ {的MessageID} /附件/ {itemattachmentid}?$扩大= Microsoft.OutlookServices.ItemAttachment /项目/附件

/api/v1.0/me/messages/ {的MessageID} /附件/ {itemattachmentid}?$扩大= Microsoft.OutlookServices.ItemAttachment /项目/ Microsoft.OutlookServices.FileAttachment /文件

/api/v1.0/me/messages/ {的MessageID} /附件/ {itemattachmentid}?$扩大= Microsoft.OutlookServices.ItemAttachment /项目/文件

显然我不确定我在做什么:P

2 个答案:

答案 0 :(得分:1)

抱歉,目前暂不支持。我们将把它放在我们的产品积压上。

答案 1 :(得分:0)

我们现在在API的Beta版本中支持此功能。您可以通过几种不同的方式从附加的消息或事件中获取附件。

通过扩展根消息

GET https://outlook.office.com/api/beta/me/messages/[message-id]?
$expand=Attachments($expand=Microsoft.OutlookServices.ItemAttachment/Item
($expand=Microsoft.OutlookServices.Event/Attachments))
  

注意:在上一个$expand我使用Microsoft.OutlookServices.Event作为类型,但您应该更改此项以匹配附加项的实际类型。对于消息,它将是Microsoft.OutlookServices.Message

示例响应(截断)

{
  "Id": "AAMkAGZjYmY1ZTIwLWI1M2UtNGNkYS05MGQyLTQyMmNhOWI4MmE1MgBGAAAAAACiItQsBUn9QIuhejMqYpj5BwBk23L_AKqTR5R9JLmwxOUMAAAAAAEMAABk23L_AKqTR5R9JLmwxOUMAABfQr6jAAA=",
  "CreatedDateTime": "2017-02-17T19:59:52Z",
  "LastModifiedDateTime": "2017-02-17T19:59:53Z",
  "ChangeKey": "CQAAABYAAABk23L+AKqTR5R9JLmwxOUMAABfVXy6",
  "Categories": [],
  "ReceivedDateTime": "2017-02-17T19:59:53Z",
  "SentDateTime": "2017-02-17T19:59:43Z",
  "HasAttachments": true,
  "InternetMessageId": "<CO2PR00MB00852CEC51A3341250BD770BE05D0@CO2PR00MB0085.namprd00.prod.outlook.com>",
  "Subject": "ItemAttachmentTest",
  "BodyPreview": "Hello!",
  "Importance": "Normal",
  "ParentFolderId": "AQMkAGZjYmY1ZTIwLWI1M2UtNGNkYS05MGQyLTQyMgBjYTliODJhNTIALgAAA6Ii1CwFSf1Ai6F6MypimPkBAGTbcv4AqpNHlH0kubDE5QwAAAIBDAAAAA==",
  "ConversationId": "AAQkAGZjYmY1ZTIwLWI1M2UtNGNkYS05MGQyLTQyMmNhOWI4MmE1MgAQAMMK8FY8x0SBhvgi8t6QP50=",
  "ConversationIndex": "AdKJWFYcwwrwVjzHRIGG+CLy3pA/nQ==",
  "IsDeliveryReceiptRequested": null,
  "IsReadReceiptRequested": false,
  "IsRead": false,
  "IsDraft": false,
  "WebLink": "https://outlook.office365.com/owa/?ItemID=AAMkAGZjYmY1ZTIwLWI1M2UtNGNkYS05MGQyLTQyMmNhOWI4MmE1MgBGAAAAAACiItQsBUn9QIuhejMqYpj5BwBk23L%2BAKqTR5R9JLmwxOUMAAAAAAEMAABk23L%2BAKqTR5R9JLmwxOUMAABfQr6jAAA%3D&exvsurl=1&viewModel=ReadMessageItem",
  "InferenceClassification": "Focused",
  "UnsubscribeData": [],
  "UnsubscribeEnabled": false,
  "Body": {
    "ContentType": "HTML",
    "Content": "Hello!"
  },
  "Sender": {
    "EmailAddress": {
      "Name": "Jason Johnston",
      "Address": "jason@mod716595.onmicrosoft.com"
    }
  },
  "From": {
    "EmailAddress": {
      "Name": "Jason Johnston",
      "Address": "jason@mod716595.onmicrosoft.com"
    }
  },
  "ToRecipients": [
    {
      "EmailAddress": {
        "Name": "Adele Vance",
        "Address": "AdeleV@MOD716595.onmicrosoft.com"
      }
    }
  ],
  "CcRecipients": [],
  "BccRecipients": [],
  "ReplyTo": [],
  "MentionsPreview": null,
  "Flag": {
    "FlagStatus": "NotFlagged"
  },
  "Attachments": [
    {
      "Id": "AAMkAGZjYmY1ZTIwLWI1M2UtNGNkYS05MGQyLTQyMmNhOWI4MmE1MgBGAAAAAACiItQsBUn9QIuhejMqYpj5BwBk23L_AKqTR5R9JLmwxOUMAAAAAAEMAABk23L_AKqTR5R9JLmwxOUMAABfQr6jAAABEgAQAE7xPNscnYFJmjqkGK0AjJc=",
      "LastModifiedDateTime": "2017-02-17T19:59:35Z",
      "Name": "Test appt with attachments!",
      "ContentType": "message/rfc822",
      "Size": 33358,
      "IsInline": false,
      "Item": {
        "Id": null,
        "CreatedDateTime": "2017-02-17T19:59:52Z",
        "LastModifiedDateTime": "2017-02-17T19:59:52Z",
        "OriginalStartTimeZone": "Eastern Standard Time",
        "OriginalEndTimeZone": "Eastern Standard Time",
        "iCalUId": "040000008200E00074C5B7101A82E00800000000D066332D2E89D201000000000000000010000000DAB182D13FA80846BA7983D8064016CC",
        "ReminderMinutesBeforeStart": 0,
        "IsReminderOn": false,
        "HasAttachments": true,
        "Subject": "Test appt with attachments!",
        "Importance": "Normal",
        "Sensitivity": "Normal",
        "IsAllDay": false,
        "IsCancelled": false,
        "IsOrganizer": true,
        "ResponseRequested": false,
        "ShowAs": "Busy",
        "Type": "SingleInstance",
        "Body": {
          "ContentType": "HTML",
          "Content": "Hello!"
        },
        "Start": {
          "DateTime": "2017-02-17T17:00:00.0000000Z",
          "TimeZone": "UTC"
        },
        "End": {
          "DateTime": "2017-02-17T17:30:00.0000000Z",
          "TimeZone": "UTC"
        },
        "Location": {
          "DisplayName": ""
        },
        "Organizer": {
          "EmailAddress": {
            "Name": "Jason Johnston",
            "Address": "jason@mod716595.onmicrosoft.com"
          }
        },
        "Attachments": [
          {
            "Id": "AAMkAGZjYmY1ZTIwLWI1M2UtNGNkYS05MGQyLTQyMmNhOWI4MmE1MgBGAAAAAACiItQsBUn9QIuhejMqYpj5BwBk23L_AKqTR5R9JLmwxOUMAAAAAAEMAABk23L_AKqTR5R9JLmwxOUMAABfQr6jAAACEgAQAE7xPNscnYFJmjqkGK0AjJcSABAAAucTv00RHEqhT3zxzdeBkg==",
            "LastModifiedDateTime": "2017-02-17T17:53:20Z",
            "Name": "OutlookSDKTest.log",
            "ContentType": "application/octet-stream",
            "Size": 5850,
            "IsInline": false,
            "ContentId": "EBEAA84020CB3C458DFFCF177291F0E8@namprd00.prod.outlook.com",
            "ContentLocation": null,
            "ContentBytes": "UmF3IElk..."
          },
          {
            "Id": "AAMkAGZjYmY1ZTIwLWI1M2UtNGNkYS05MGQyLTQyMmNhOWI4MmE1MgBGAAAAAACiItQsBUn9QIuhejMqYpj5BwBk23L_AKqTR5R9JLmwxOUMAAAAAAEMAABk23L_AKqTR5R9JLmwxOUMAABfQr6jAAACEgAQAE7xPNscnYFJmjqkGK0AjJcSABAASt-usjVlxUufvpCupiLncA==",
            "LastModifiedDateTime": "2017-02-17T17:11:28Z",
            "Name": "OutlookWebAddIn1.xml",
            "ContentType": "application/xml",
            "Size": 12015,
            "IsInline": false,
            "ContentId": "49652CE21E82F74790BF2450DDA4B27E@namprd00.prod.outlook.com",
            "ContentLocation": null,
            "ContentBytes": "77u/PD94..."
          }
        ]
      }
    }
  ]
}

通过附件ID

GET https://outlook.office.com/api/beta/me/messages/[message-id]/
attachments/[attach-id]?$expand=Microsoft.OutlookServices.ItemAttachment/Item

示例响应(截断)

{
  "Id": "AAMkAGZjYmY1ZTIwLWI1M2UtNGNkYS05MGQyLTQyMmNhOWI4MmE1MgBGAAAAAACiItQsBUn9QIuhejMqYpj5BwBk23L_AKqTR5R9JLmwxOUMAAAAAAEMAABk23L_AKqTR5R9JLmwxOUMAABfQr6jAAABEgAQAE7xPNscnYFJmjqkGK0AjJc=",
  "LastModifiedDateTime": "2017-02-17T19:59:35Z",
  "Name": "Test appt with attachments!",
  "ContentType": "message/rfc822",
  "Size": 33358,
  "IsInline": false,
  "Item": {
    "Id": null,
    "CreatedDateTime": "2017-02-17T19:59:52Z",
    "LastModifiedDateTime": "2017-02-17T19:59:52Z",
    "OriginalStartTimeZone": "Eastern Standard Time",
    "OriginalEndTimeZone": "Eastern Standard Time",
    "iCalUId": "040000008200E00074C5B7101A82E00800000000D066332D2E89D201000000000000000010000000DAB182D13FA80846BA7983D8064016CC",
    "ReminderMinutesBeforeStart": 0,
    "IsReminderOn": false,
    "HasAttachments": true,
    "Subject": "Test appt with attachments!",
    "Importance": "Normal",
    "Sensitivity": "Normal",
    "IsAllDay": false,
    "IsCancelled": false,
    "IsOrganizer": true,
    "ResponseRequested": false,
    "ShowAs": "Busy",
    "Type": "SingleInstance",
    "Body": {
      "ContentType": "HTML",
      "Content": "Hello!"
    },
    "Start": {
      "DateTime": "2017-02-17T17:00:00.0000000Z",
      "TimeZone": "UTC"
    },
    "End": {
      "DateTime": "2017-02-17T17:30:00.0000000Z",
      "TimeZone": "UTC"
    },
    "Location": {
      "DisplayName": ""
    },
    "Organizer": {
      "EmailAddress": {
        "Name": "Jason Johnston",
        "Address": "jason@mod716595.onmicrosoft.com"
      }
    },
    "Attachments": [
      {
        "Id": "AAMkAGZjYmY1ZTIwLWI1M2UtNGNkYS05MGQyLTQyMmNhOWI4MmE1MgBGAAAAAACiItQsBUn9QIuhejMqYpj5BwBk23L_AKqTR5R9JLmwxOUMAAAAAAEMAABk23L_AKqTR5R9JLmwxOUMAABfQr6jAAACEgAQAE7xPNscnYFJmjqkGK0AjJcSABAAAucTv00RHEqhT3zxzdeBkg==",
        "LastModifiedDateTime": "2017-02-17T17:53:20Z",
        "Name": "OutlookSDKTest.log",
        "ContentType": "application/octet-stream",
        "Size": 5850,
        "IsInline": false,
        "ContentId": "EBEAA84020CB3C458DFFCF177291F0E8@namprd00.prod.outlook.com",
        "ContentLocation": null,
        "ContentBytes": "UmF3IElk..."
      },
      {
        "Id": "AAMkAGZjYmY1ZTIwLWI1M2UtNGNkYS05MGQyLTQyMmNhOWI4MmE1MgBGAAAAAACiItQsBUn9QIuhejMqYpj5BwBk23L_AKqTR5R9JLmwxOUMAAAAAAEMAABk23L_AKqTR5R9JLmwxOUMAABfQr6jAAACEgAQAE7xPNscnYFJmjqkGK0AjJcSABAASt-usjVlxUufvpCupiLncA==",
        "LastModifiedDateTime": "2017-02-17T17:11:28Z",
        "Name": "OutlookWebAddIn1.xml",
        "ContentType": "application/xml",
        "Size": 12015,
        "IsInline": false,
        "ContentId": "49652CE21E82F74790BF2450DDA4B27E@namprd00.prod.outlook.com",
        "ContentLocation": null,
        "ContentBytes": "77u/PD94..."
      }
    ]
  }
}