Search code examples
office-jsoutlook-restapioutlook-web-addinsmicrosoft-graph-api

Get custom property set in Outlook Add-In via Microsoft Graph


Let's say I have in my Outlook Add-In (using Office.js) following code running on a compose form of an appointment:

const item = Office.context.mailbox.item;
item.loadCustomPropertiesAsync((result) => {
    const props = result.value;
    const testProp = props.get("my_prop");
    console.log("CUSTOM_PROP", testProp);
    props.set("my_prop", "test_value");
    props.saveAsync((saveResult) =>
        console.log("SAVE_CUSTOM_PROP", saveResult));
});

I see, that it actually is saved on the event.

And now a bunch of questions regarding those custom properties:

  1. But are those somehow related to extended properties?

  2. Are those properties somehow accessible through Outlook REST API or Microsoft Graph?

  3. Can I create a push notifications subscription using Microsoft Graph with a filter based on those properties? (I know I can based on extended properties)

  4. If the answer to above question is "no", and the custom properties are only accessible through the add-in which created them, is there a way to create a extended property to an event from the add-in, even if it's not saved?

To explain why I'm asking - I'm creating an add-in, which allows to "connect" an appointment with our 3rd party system, and keep that appointment in sync with our object.

So when a button is clicked on the compose form, I:

  • save the appointment and get the event-id,
  • store it in our system, to do the sync from our system to the appointment.
  • add an extended property in our system using Microsoft Graph for that appointment

In the first use of the add-in, the user authenticates, and I create a push notification subscription for events with our extended property, to do the sync from Outlook to our system.

It works great on OWA, but now as we really need to support desktop, two major issues are arising:

  • Outlook for Mac: no saveAsync method, thus no way to get the event's id, I was thinking about adding some custom property, and then let the push notification inform our system, that an event was created which needs to be synced with out system.

  • Outlook for PC: there is the saveAsync method, but the callback is executed when the appointment is saved locally, not on the server, thus I can't know when exactly the event has been created and I can do some Microsoft Graph calls on that event.

Answer to my first question, and/or any tips about my use case would be more than welcome.


Solution

  • TL;DR; Yes it is possible to read custom properties set by Office.js api loadCustomPropertiesAsync using REST APIs You need to create a REST call query that looks like

    string addinManifestId = "<your manifest guid here>";//lower cases
    string prop = @"String {00020329-0000-0000-C000-000000000046} Name"+ string.Format(" cecp-{0}", addinManifestId );
    var url = $"<apiEndpoint>/messages/<youritemid>?$expand=SingleValueExtendedProperties($filter=PropertyId eq '{propertyname}')";
    

    More info

    The documentation is available here https://msdn.microsoft.com/en-us/library/hh968549(v=exchg.80).aspx

    I had a similar problem when I needed to handle "sent mail" for my add-in Keluro. I implemented something really close to your approach with a web hook on REST API. To my knowledge it is the only way to handle sent items. Consider upvoting this https://officespdev.uservoice.com/forums/224641-feature-requests-and-feedback/suggestions/10964871-add-itemsend-event-so-add-in-can-cancel-email