Search code examples
microsoft-graph-api

SendMail with flag with a due date return ErrorInvalidArgumentError


I'm trying to send an email with a flag which has a due date. The following request in the graph explorer works.
POST https://graph.microsoft.com/v1.0/me/sendMail

{
  "message": {
    "subject": "Meet for lunch?",
    "body": {
      "contentType": "Text",
      "content": "The new cafeteria is open."
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "vincent@baywet.onmicrosoft.com"
        }
      }
    ],
    "flag": {
      "flagStatus": "flagged"
    }
  },
  "saveToSentItems": "false"
}

And the same request with the following payload fails

{
  "message": {
    "subject": "Meet for lunch?",
    "body": {
      "contentType": "Text",
      "content": "The new cafeteria is open."
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "vincent@baywet.onmicrosoft.com"
        }
      }
    ],
    "flag": {
      "flagStatus": "flagged",
      "dueDateTime": {
        "timeZone": "Pacific Standard Time",
        "dateTime": "2019-01-25T19:58:27"
      }
    }
  },
  "saveToSentItems": "false"
}

With the following error message

{
    "error": {
        "code": "ErrorInvalidArgument",
        "message": "The request is invalid.",
        "innerError": {
            "request-id": "5e335c05-071b-4b23-8511-006db9e6e883",
            "date": "2019-01-24T20:03:45"
        }
    }
}

Note that the only difference is the following node (due date)

"dueDateTime": {
        "timeZone": "Pacific Standard Time",
        "dateTime": "2019-01-25T19:58:27"
      }

According to the documentation, I'm supposed to pass-in a DateTimeTimeZone object, and even if this specific article doesn't have a sample, my object looks correct according to similar examples.
No limitations are listed in the documentation as well as the known issues so I'm wondering what's wrong with this payload and how can I set a flag with a due date when sending an email?


Solution

  • Sorry for the late reply. I finally got air 9 months later to dig in with an engineer. Looking in the back end logic. Both start date and due date have to be set for this to work.

    So you'd need to do this

      "flag": {
          "flagStatus": "flagged",
          "dueDateTime": {
            "timeZone": "Pacific Standard Time",
            "dateTime": "2019-12-25T19:58:27"
          },
          "startDateTime": {
            "timeZone": "Pacific Standard Time",
            "dateTime": "2019-11-25T19:58:27"
          }
    

    I am going to get the docs updated on this.