1
votes

I would like to add some custom data to emails and to be able to filter them by using GraphAPI.
So far, I was able to create a Schema Extension and it gets returned successfully when I query https://graph.microsoft.com/v1.0/schemaExtensions/ourdomain_EmailCustomFields:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#schemaExtensions/$entity",
    "id": "ourdomain_EmailCustomFields",
    "description": "Custom data for emails",
    "targetTypes": [
        "Message"
    ],
    "status": "InDevelopment",
    "owner": "hiding",
    "properties": [
        {
            "name": "MailID",
            "type": "String"
        },
        {
            "name": "ProcessedAt",
            "type": "DateTime"
        }
    ]
}

Then I patched a specific message https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/Messages/hidingmessageid:

PATCH Request
{"ourdomain_EmailCustomFields":{"MailID":"12","ProcessedAt":"2020-05-27T16:21:19.0204032-07:00"}}

The problem is that when I select the message, the added custom data doesn't appear by executing a GET request: https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/Messages?$top=1&$select=id,subject,ourdomain_EmailCustomFields

Also, the following GET request gives me an error.
Request: https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/Messages?$filter=ourdomain_EmailCustomFields/MailID eq '12'

Response:

{
    "error": {
        "code": "RequestBroker--ParseUri",
        "message": "Could not find a property named 'e2_someguid_ourdomain_EmailCustomFields' on type 'Microsoft.OutlookServices.Message'.",
        "innerError": {
            "request-id": "someguid",
            "date": "2020-05-29T01:04:53"
        }
    }
}

Do you have any ideas on how to resolve the issues? Thank you!

1

1 Answers

2
votes

I took your schema extension and copied and pasted it into my tenant, except with a random app registration I created as owner. then patched an email with your statement, and it does work correctly.

A couple of things here, I would verify using microsoft graph explorer that everything is correct. eg, log into graph explorer with an admin account https://developer.microsoft.com/en-us/graph/graph-explorer# first make sure the schema extensions exists

run a get request for

https://graph.microsoft.com/v1.0/schemaExtensions/DOMAIN_EmailCustomFields

It should return the schemaextension you created. then

Run a get request for the actual message you patched not all messages that you filtered for now.

https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/Messages/MESSAGEID?$select=DOMAIN_EmailCustomFields

here the response should be the email you patched and your EmailCustomField should be in the data somewhere, if it is not, that means that your patch did not work.

then you can run patch again from graph explorer

I did all this from graph explorer, easiest way to confirm.

two other things, 1) maybe the ?$top=1 in your get first message isn't the same message that you patched?

2) as per the documentation, you cannot use $filter for schema extensions with the message entity. (https://docs.microsoft.com/en-us/graph/known-issues#filtering-on-schema-extension-properties-not-supported-on-all-entity-types) So that second Get will never work.

Hopefully this helps you troubleshoot.