0
votes

I'm looking for some help formatting schema extension data in Microsoft's Graph API. I've been able to successfully send Office 365 messages in code and through the Graph Explorer using this body:

{
  "message": {
    "subject": "Test Subject",
    "body": {
      "contentType": "Text",
      "content": "Test Body "
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "foo@email.com"
        }
      }
    ]
  }
}

I created a schema extension and promoted it to "Available" status. I can query the extension to verify it's available and get this response body:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#schemaExtensions",
    "value": [
        {
            "id": "extc5bnq6uk_TestExtension",
            "description": "Test Extension",
            "targetTypes": [
                "Message"
            ],
            "status": "Available",
            "owner": "mysecretclienttenantgoeshere",
            "properties": [
                {
                    "name": "ValueOne",
                    "type": "String"
                },
                {
                    "name": "ValueTwo",
                    "type": "String"
                }
            ]
        }
    ]
}

So far I haven't been able to append extension data to a new message. I've tried formatting my request body like this:

{
  "message": {
    "subject": "Test Subject",
    "body": {
      "contentType": "Text",
      "content": "Test Body "
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "foo@email.com"
        }
      }
    ],
    "extc5bnq6uk_TestExtension": {
      "ValueOne": "TestValue",
      "ValueTwo": "TestValue"
    }
  }
}

and like this:

{
  "message": {
    "subject": "Test Subject",
    "body": {
      "contentType": "Text",
      "content": "Test Body "
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "foo@email.com"
        }
      }
    ],
    "extensions":[
    {
        "extc5bnq6uk_TestExtension" : {
            "ValueOne" : "TestValue"
            "ValueTwo" : "TestValue"
        }
    }
    ]
  }
}

Both formats return a 400 code with response body:

{
    "error": {
        "code": "RequestBodyRead",
        "message": "The property 'extc5bnq6uk_TestExtension' does not exist on type 'Microsoft.OutlookServices.Message'. Make sure to only use property names that are defined by the type or mark the type as open type.",
        "innerError": {
            "request-id": "21792fd0-44d1-42aa-8d51-f8abc92cbd04",
            "date": "2018-08-14T16:39:31"
        }
    }
}

I'm posting to this URL in the graph explorer:

https://graph.microsoft.com/v1.0/me/sendMail

and to the "messages" and "sendMail" endpoints in code.

2
That documentation is for open type extensions, which are working fine.Jeff Beck
That is also for open types @jdweng. This question is specific to schema extensions. Here's the documentation I'm following: developer.microsoft.com/en-us/graph/docs/concepts/…Jeff Beck
I would use a sniffer like wireshark or fiddler . And capture the good results and the bad to see if you see a pattern. The link is using http 1.1. Not sure what you code is sending. Http 1.0 is stream mode while http 1.1 is chunk mode. Chunk Mode requires send a Next Chunk message, otherwise, a timeout occurs. I have never gotten 1.1 to work with a httpclient in c#. I do not know what client is being used in your code. But using a sniffer may give more info. You may want to change 1.1 to 1.0 and see if that works.jdweng

2 Answers

1
votes

I found the answer in the Known Limitations of the documentation. Certain resource types, including messages, have to be done in two stages, an initial post and then a follow up patch.

Creating the message and then patching with this JSON returned a valid response.

{
    "extc5bnq6uk_TestExtension": {
        "ValueOne": "Test Value One",
        "ValueTwo": "Test Value Two"
    }
}

Unfortunately, another limitation for schema extensions on messages is that they can't be used to filter messages, which is what I was ultimately after.

Filtering on schema extension properties (using the $filter expresssion) is not supported for Outlook entity types - contact, event, message, or post.

0
votes

Jeff

Based on your question you posted, you have created a schemaExtension successfully. I think you want to send an email with this schemaExtension, but when you send an email with this schemaExtension, we get the 400 code in the response.

Based on my test, I think we can use the request body as blow.

1.Create a schemaExtension like this:

{
   "@odata.context":"https://graph.microsoft.com/v1.0/$metadata#schemaExtensions/$entity",
   "id":"{extensionId}",
   "description":"sample description",
   "targetTypes":[
       "Message"
    ],
   "status":"Available",
   "owner":"{owner id}",
   "properties":[
      {
          "name":"p1",
          "type":"String"
      },
      {
          "name":"p2",
          "type":"String"
      }
    ]
  }
  1. Create a message

POST https://graph.microsoft.com/v1.0/me/messages

{
   "message":{
      "subject":"Meet for lunch?",
      "body":{
          "contentType":"Text",
          "content":"The new cafeteria is open."
       },
      "toRecipients":[
          {
              "emailAddress":{
                  "address":"{toRecipients email address}"
              }
          }
      ],
      "extensions":[
          {
              "@odata.type":"Microsoft.Graph.OpenTypeExtension",
              "extensionName":"{extensionName}",
              "p1":"Wingtip Toys",
              "p2":"10000"
          }
      ]
  },
  "saveToSentItems":"false"
}
  1. when we send this message with the request, we will get the 202 code. The {toRecipients email address} will receive the email.