Azure Logic Apps - Moving Email Message with Move Message action

Go To StackoverFlow.com

0

I'm fairly new to Logic Apps and I have an app that I'm trying to get to move an email to a subfolder of the Inbox in a shared mailbox, but I'm trying to generate the path based on the date and I cannot for the life of me get it to work. I don't know if my path syntax is wrong or what.

The subfolder structure is basically

- Inbox
 - 2018
  - Jan
  - Feb
  - Mar
  - Etc

And I'm trying to generate the path based off the year and the month using the Expressions part of a field. I've got an expression that generates the path for me

concat('Inbox\',formatDateTime(convertFromUtc(utcNow(),'Mountain Standard Time'),'MMM'),'\',formatDateTime(convertFromUtc(utcNow(),'Mountain Standard Time'),'yyyy'))

When the logic app runs this generates the correct path string of Inbox\2018\Jan but when the Move Email action runs it always escapes the backslash and then says it can't find the folder Inbox\\2018\\Jan.

So I either have this format wrong, I can't put the email in a subfolder or there's another way to do this.

I tried using the folder picker to pick one of the month subfolders and then peeked at the code and it uses some base64 encoded string for the path. I've pasted below what the peeked code shows

{
    "inputs": {
        "host": {
            "connection": {
                "name": "@parameters('$connections')['office365']['connectionId']"
            }
        },
        "method": "post",
        "path": "/Mail/Move/@{encodeURIComponent(triggerBody()?['Id'])}",
        "queries": {
            "folderPath": "Id::AAMkADRmOTgyMDI1LThkODYtNDMwYy1iYThiLTIzODQwN2Y1OGMzYQAuAAAAAAA6K3dJssnITb8NwkAsBOo7AQBaJ9ZTcg-MSoOEUUjjUdOAAAAD0nvYAAA="
        },
        "authentication": "@parameters('$authentication')"
    },
    "metadata": {
        "Id::AAMkADRmOTgyMDI1LThkODYtNDMwYy1iYThiLTIzODQwN2Y1OGMzYQAuAAAAAAA6K3dJssnITb8NwkAsBOo7AQBaJ9ZTcg-MSoOEUUjjUdOAAAAD0nvYAAA=": "Jan"
    }
}

Does anyone know how I would be able to move an email to a subfolder without using the folder picker?

Edit: Since posting I've also tried using the following strings that also do not work

Inbox/2018/Jan
Inbox:/2018/Jan
/Inbox/2018/Jan
2018-01-24 18:41
by Martin
Which connector are you using? Office365, Outlook, Gmail - Paco de la Cruz 2018-01-24 22:58
From the code, seems to be Office36 - Aman Arneja - MSFT 2018-01-25 02:16


0

You cant really have the path in terms of a hierarchy folder structure in this particular logic app.

If you look at the Documentation for Office 365 Mail rest operations @

https://msdn.microsoft.com/office/office365/api/mail-rest-operations#MoveCopyMessages

You will notice that to Move messages what you actually need is a folder ID. Also if you look at the logic app Designer, when you select a folder directly from there and then look at the code view you will see an ID. It looks something like

 "method": "post",
                    "path": "/Mail/Move/@{encodeURIComponent(triggerBody()?['Id'])}",
                    "queries": {
                        "folderPath": "Id::AAMkADZmZDQ5OWNhLTU3NzQtNDRlZC1iMDRlLTg5NTA1NGM3NWJlZgAuAAAAAAAhZj7Qt8LySYhKvlgbXRNVAQBT8bGPBJK8Qqoy01hgwH4rAAEJysaQAAA="
                    }
                },
                "metadata": {
                    "Id::AAMkADZmZDQ5OWNhLTU3NzQtNDRlZC1iMDRlLTg5NTA1NGM3NWJlZgAuAAAAAAAhZj7Qt8LySYhKvlgbXRNVAQBT8bGPBJK8Qqoy01hgwH4rAAEJysaQAAA=": "Jan"
                },

The FolderID is unique to every folder. One easy way to find the FolderIDs for a folder is to use

https://developer.microsoft.com/en-us/graph/graph-explorer#

and after signing in , posting

https://graph.microsoft.com/beta/me/mailFolders/Inbox/childFolders

as the query which will give you the ChildFolders for Inbox the values will look something like the following for every folder

"value": [
        {
            "id": "AAMkADZmZDQ5OWNhLTU3NzQtNDRlZC1iMDRlLTg5NTA1NGM3NWJlZgAuAAAAAAAhZj7Qt8LySYhKvlgbXRNVAQBT8bGPBJK8Qqoy01hgwH4rAAEJysWPAAA=",
            "displayName": "AZCommunity",
            "parentFolderId": "AAMkADZmZDQ5OWNhLTU3NzQtNDRlZC1iMDRlLTg5NTA1NGM3NWJlZgAuAAAAAAAhZj7Qt8LySYhKvlgbXRNVAQDX8XL9o4tkR5vF5sEdh44eAIYnQnhhAAA=",
            "childFolderCount": 0,
            "unreadItemCount": 5,
            "totalItemCount": 169,
            "wellKnownName": null
        },

For what you are trying to do, you will have to do additional work to map the folders to the folder ID and then assign using that. I would suggest using Azure Functions to easily do this.

2018-01-25 03:20
by Aman Arneja - MSFT
Also add this as a feature request @ https://feedback.azure.com/forums/287593-logic-apps for the team to look at and add as they develop this use case. - Aman Arneja - MSFT 2018-01-25 05:15
I've created a C# function and after a while have figured out how the default one seems to work. Is there any easy to understand resources for connecting to the Microsoft Graph and running a query using C# - Martin 2018-01-26 22:04
Ads