0
votes

I want to be able approve a moderation request through Graph API. I have referred to Approve Moderation Request. I was not able to get it to work. Although, there is a PowerShell script available at EWS Managed API and Powershell How-To Series Part 11 Moderation that I managed to get working.

This is not a supported feature in Graph API and therefore requires some tinkering. I would like some guidance on how to do this.

This is the JSON I am sending to the end point https://graph.microsoft.com/v1.0/me/sendMail

{
    "message": {
        "subject": "Approve:MessageName"
    },
    "toRecipients": [
        {
            "emailAddress": {
                "name": "Microsoft Exchange",
                "address": "[email protected]"
            }
        }
    ],
    "singleValueExtendedProperties": [
        {
            "id": "Binary 0x31",
            "value": "7gd324tgcxJJNkEuxk2DP2Xk+M/fxw=="
        },
        {
            "id": "String 0x001A",
            "value": "IPM.Note.Microsoft.Approval.Reply.Approve"
        }
    ]
}

This is the response I receive

{
    "error": {
        "code": "ErrorInvalidRecipients",
        "message": "At least one recipient isn't valid., A message can't be sent because it contains no recipients.",
        "innerError": {
            "date": "2020-08-19T23:40:07",
            "request-id": "7g5h732v-6uhb-3212-b6f1-43f6eeb139wq"
        }
    }
}

Any help would be appreciated.

1

1 Answers

1
votes

You have a syntax issue in your Json request eg look closely at the Message after subject you have a closing } which means the only thing your posting is the subject of the message it should be

{
    "message": {
        "subject": "Approve:MessageName",
        "toRecipients": [
            {
                "emailAddress": {
                    "name": "Microsoft Exchange",
                    "address": "address.com"
                }
            }
        ],
        "singleValueExtendedProperties": [
            {
                "id": "Binary 0x31",
                "value": "7gd324tgcxJJNkEuxk2DP2Xk+M/fxw=="
            },
            {
                "id": "String 0x001A",
                "value": "IPM.Note.Microsoft.Approval.Reply.Approve"
            }
        ]
    }
}

Additional

To make this work correctly you need to get the Approval Request from an app rovers mailbox for the Graph a query like this

https://graph.microsoft.com/v1.0/me/mailFolders('Inbox')/messages?$filter=singleValueExtendedProperties/any(ep:ep/id eq 'String 0x001a' and ep/value eq 'IPM.Note.Microsoft.Approval.Request')&$expand=singleValueExtendedProperties($filter%3D(Id eq 'Binary 0x0031') or (Id eq 'String 0x0E1D'))

This will give you the report tag 0x0031 value that you need to use in your Send and you also need to include the Approve Verb Extended property

{
                    id = "String {00062008-0000-0000-C000-000000000046} Id 0x8524"
                    value = "Approve"
 }

I converted the script from my blog which I'll get around to posting this week that just approves the last email in a Mailbox you can look at it https://github.com/gscales/Powershell-Scripts/blob/master/Graph101/Moderation.ps1 (look at Invoke-ApproveModerationRequest)