How to retrieve FileAttachment from ItemAttachment

2020-03-31 03:32发布

问题:

See this thread for more context. After figuring out how to retrieve ItemAttachments from messages via the Office 365 Mail REST API, I'm now running into another issue: retrieving FileAttachments from ItemAttachments.

The API guides don't cover this (as far as I can tell). When I do retrieve an ItemAttachment, the "HasAttachment" key has a value of "true," but I can't figure out how to retrieve it.

I've (blindly) tried the following URIs:

/api/v1.0/me/messages/{messageid}/Attachments/{itemattachmentid}?$expand=Microsoft.OutlookServices.ItemAttachment/Item/Attachments

/api/v1.0/me/messages/{messageid}/Attachments/{itemattachmentid}?$expand=Microsoft.OutlookServices.ItemAttachment/Item/Microsoft.OutlookServices.FileAttachment/File

/api/v1.0/me/messages/{messageid}/Attachments/{itemattachmentid}?$expand=Microsoft.OutlookServices.ItemAttachment/Item/File

Clearly I'm not sure what I'm doing :P

回答1:

Sorry, this isn't currently supported today. We will put this on our product backlog.



回答2:

We now support this in the Beta version of the API. You can get the attachments from an attached message or event in a couple of different ways.

Via expansion on the root message

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

Note: In the last $expand I used Microsoft.OutlookServices.Event as the type, but you should change this to match the actual type of the attached item. For a message, it would be Microsoft.OutlookServices.Message.

Example Response (truncated)

{
  "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..."
          }
        ]
      }
    }
  ]
}

Via Attachment ID

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

Example Response (truncated)

{
  "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..."
      }
    ]
  }
}