none
Is it possible to filter email using EntryID (PR_ENTRYID) with Outlook REST API? or how to filter emails using binary mapi properties like ENTRY_ID? RRS feed

  • Question

  • We are currently using EWS Managed APIs in our application and looking to migrate to use Outlook REST API approach. I am new to Outlook REST API world and looking for some inputs.

    I am trying to fetch email from exchange using PR_ENTRYID with REST API and retrieve its properties, however always facing error like below:

    Response status code does not indicate success: 400 (Bad Request).

    Endpoint used : https://outlook.office365.com/api/v2.0/me/messages?

    Code:

    Above endpoint is appended with below filter:

    "$filter=SingleValueExtendedProperties/any(ep: ep/PropertyId eq 'Binary 0x0fff' and cast (ep/Value, Edm.Binary) eq '" + entryId + "')";

    where entryId is "00000000224A6557586868FH8N6765SZ6F78768686C9786R7658E8686860886D8768676C8B6CV75V7C57S6F5S8FSF7S9F7D86GD7G57D6G86D84000000"

    also tried entryId of below form with no luck: "AAAAACJKsh5bmbBdknCdkkjAAdjhV76ssn876fBDJg76jdkBfnnnkbslnKns76229873qHGHGnPPSHSFH+gdgf8BmF8aJdgaAAA=="

    Please note that I am able to expand properties as mentioned here, however unable to filter/fetch email with that property. I have followed official documentation at official documentation

    Any help is highly appreciated.

    Thanks.



    sureshh...

    Friday, November 9, 2018 10:19 PM

Answers

  • If you have the EntryId you can use that in MAPI to open an item directly, in EWS you can convert that Id using the ConverId operation to a EWSid and then bind to that Item directly. In the Graph API you can also convert and EntryId to the RESTId that is usable to directly access the Item.

    >>Little more background about my requirement: We have Outlook plugin with which we fetch MailItem EntryID and want to find InternetMessageId for that MailItem using Outlook REST API so we can use MessageId for future reference for that MailItem.

    So getting the InternetMessageId in an Outlook Plugin is pretty basic if you use the PropertyAccessor https://docs.microsoft.com/en-us/office/vba/api/outlook.propertyaccessor.getproperty and the pidtaginternetmessageid  https://docs.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtaginternetmessageid-canonical-property

    • Marked as answer by sureshh Friday, February 8, 2019 6:25 PM
    Monday, November 12, 2018 10:00 PM

All replies

  • We are currently using EWS Managed APIs in our application and looking to migrate to use Outlook REST API approach. I am new to Outlook REST API world and looking for some inputs.

    I am trying to fetch email from exchange using PR_ENTRYID with REST API and retrieve its properties, however always facing error like below:

    Response status code does not indicate success: 400 (Bad Request).

    Endpoint used : https://outlook.office365.com/api/v2.0/me/messages?

    Code:

    Above endpoint is appended with below filter:

    "$filter=SingleValueExtendedProperties/any(ep: ep/PropertyId eq 'Binary 0x0fff' and cast (ep/Value, Edm.Binary) eq '" + entryId + "')";

    where entryId is "00000000224A6557586868FH8N6765SZ6F78768686C9786R7658E8686860886D8768676C8B6CV75V7C57S6F5S8FSF7S9F7D86GD7G57D6G86D84000000"

    also tried entryId of below form with no luck: "AAAAACJKsh5bmbBdknCdkkjAAdjhV76ssn876fBDJg76jdkBfnnnkbslnKns76229873qHGHGnPPSHSFH+gdgf8BmF8aJdgaAAA=="

    Please note that I am able to expand properties as mentioned here, however unable to filter/fetch email with that property. I have followed official documentation at official documentation

    Any help is highly appreciated.

    Thanks.



    sureshh...

    Friday, November 9, 2018 10:13 PM
  • I recommend that you post this in the Development Forum:  http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/threads



    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!

    Friday, November 9, 2018 10:48 PM
  • No you can't filter by the PR_ENTRYID or any of the identifier properties but you shouldn't need to because with these properties you can access the item directly.  

    Generally you can convert the EWSId to a RestId by just making the Base64 EWSid URI safe doing a replace see https://social.technet.microsoft.com/Forums/exchange/en-US/ccf58133-c4f6-4ed8-a130-418838e38372/exchange-onlinemail-apphow-to-convert-a-item-id-in-rest-format-to-an-item-id-in-ews-format?forum=exchangesvrdevelopment

    I would also suggest you look at the Graph Endpont rather then the Oultook one unless you have a reason to use the Outlook endpoint suggest reading https://docs.microsoft.com/en-us/outlook/rest/compare-graph-outlook

    The Graph now has an operation in Beta that will allow you to do conversion so in the context you could easily convert PR_EntryId to RESTId that would be usable in the Graph see https://github.com/microsoftgraph/microsoft-graph-docs/blob/master/api-reference/beta/api/user_translateexchangeids.md

    Cheers
    Glen

    Sunday, November 11, 2018 11:17 PM
  • Thanks Glen for your response. I am bit confused with your first statement - "...but you shouldn't need to because with thee properties you can access the item directly."

    Can you elaborate on the same?

    Little more background about my requirement: We have Outlook plugin with which we fetch MailItem EntryID and want to find InternetMessageId for that MailItem using Outlook REST API so we can use MessageId for future reference for that MailItem.

    Thanks again.


    sureshh...

    Monday, November 12, 2018 8:43 PM
  • If you have the EntryId you can use that in MAPI to open an item directly, in EWS you can convert that Id using the ConverId operation to a EWSid and then bind to that Item directly. In the Graph API you can also convert and EntryId to the RESTId that is usable to directly access the Item.

    >>Little more background about my requirement: We have Outlook plugin with which we fetch MailItem EntryID and want to find InternetMessageId for that MailItem using Outlook REST API so we can use MessageId for future reference for that MailItem.

    So getting the InternetMessageId in an Outlook Plugin is pretty basic if you use the PropertyAccessor https://docs.microsoft.com/en-us/office/vba/api/outlook.propertyaccessor.getproperty and the pidtaginternetmessageid  https://docs.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtaginternetmessageid-canonical-property

    • Marked as answer by sureshh Friday, February 8, 2019 6:25 PM
    Monday, November 12, 2018 10:00 PM
  • Thanks much Glen. Look like I don't need to do what I am trying to do here - use EntryId and then find MessageId via REST API. Instead I tried the way you mentioned and able to get MessageId using PropertyAccessor for emails in my Outlook plugin.

    sureshh...

    Tuesday, November 13, 2018 8:00 PM
  • Hi Glen,

    Apparently this solution worked only when Outlook is in Online mode and not when Connected to Exchange (Cached mode). Any suggestions on how to fetch MessageID in both Outlook Online and Cached modes?

    1. for emails already sent

    2. for new emails being sent. My understanding here is unless email hits Exchange Transport wont tag that email with MessageID at all and so we can't get MessageID before it lands in Sent Items folder for new emails.

    Appreciate your help.

    Thanks.


    sureshh...

    Friday, February 8, 2019 6:29 PM
  • Sounds like you might need to create a custom property on the Message at send then you can search for that later. Or just wait until you see the Item in the SentItems folder (eg it will sit in the Outbox until sent) when it hits the sendItem it should have the MessagId.

    Cheers
    Glen

    Monday, February 11, 2019 2:01 AM