user1649304
user1649304

Reputation:

Microsoft Graph createReply does not add content

I am writing an asp.net c# application that makes calls to the microsoft graph api in order to reply to and send emails, however there seems to be a bug in the /me/messages/{id}/createReply api call. The documentation states that the content requires a "comment" property that gets added as the unique content to a message reply draft. It doesn't.

I've tested with actual code and by using Microsoft Graph Explorer to create the requests manually and each time the comment property is ignored and a draft reply containing only quoted text from the original message is created. Is the documentation simply incorrect?

If you omit the comment property entirely, no error is thrown to show that the required property is even missing.

Upvotes: 0

Views: 905

Answers (2)

VBobCat
VBobCat

Reputation: 2732

Very late, sorry, but you can at least add your own text to the reply sending a body like that:

{
    "comment": "<p>Dear madam or sir,</p><p>(reply text)</p><p>Kind regards,</p>"
}

Upvotes: 0

Peyman
Peyman

Reputation: 312

I was struggling with this issue for several hours. Graph API are really obscure. Anyway I have solved that in this way. This is PHP but I am sure there is no difference and concept is the same.

Step 1: You create a draft using createReply API. You should keep in mind that request has no body. so you are just creating a simple draft without any content or attachment or anything from yourself.

$graph = new Graph();
    $graph->setAccessToken($token);

    try {
        $draftedMessage = $graph->createRequest("POST", "/me/messages/{$id}/createReply")
            ->setReturnType(Model\Message::class)
            ->execute();

Step 2: Next you should update your drafted email with reply content and/or attachment.

$body = $draftedMessage->getBody()->getContent();
        $updatedBodyContent = $comment . '\n' . $body;
        $itemBody = new Model\ItemBody();
        $contentType = new Model\BodyType(Model\BodyType::HTML);
        $itemBody->setContentType($contentType);
        $itemBody->setContent($updatedBodyContent);
        $draftedMessage->setBody($itemBody);

        $updatedMessage = $graph->createRequest("PATCH", "/me/messages/{$draftedMessage->getId()}")
            ->attachBody($draftedMessage)
            ->execute();
    } catch(RequestException $e){
        return response()->json(['status' => false, 'message' => $e->getMessage()]);
    }

There is no way to add content when creating draft at the same time. Maybe you should call async to avoid the delay on user end. Please let me know if you faced any problem.

Upvotes: 1

Related Questions