creating logic app driven by http trigger and send email

We can easily create a logic app that run "When http request is triggered" and then send out email. 

The logic app looks something like this :- 


We will use the following json to define out schema 

{"receipient": "test@example.com","title": "Hello","message": "This is a test"}

And this us what our request body JSON schema would look like


Then we will create "Send an email (v2)". In our send email parameter setup, it looks something like this.

When our http triggers completes, it returns a json but it is also a STRING.

And we need to be able to convert it into a json otherwise you will get the following errors :-

Unable to process template language expressions in action 'Send_an_email_(V2)' inputs at line '0' and column '0': 'The template language expression 'triggerBody()?['receipient']' cannot be evaluated because property 'receipient' cannot be selected. Property selection is not supported on values of type 'String'. Please see https://aka.ms/logicexpressions for usage details.'.

You can also see it is a string



And the final code looks something like this :-


And the code 

{
    "definition": {
        "metadata": {
            "notes": {}
        },
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "contentVersion": "1.0.0.0",
        "triggers": {
            "When_an_HTTP_request_is_received": {
                "type": "Request",
                "kind": "Http",
                "inputs": {
                    "method": "POST",
                    "schema": {
                        "type": "object",
                        "properties": {
                            "receipient": {
                                "type": "string"
                            },
                            "title": {
                                "type": "string"
                            },
                            "message": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        },
        "actions": {
            "Send_an_email_(V2)": {
                "type": "ApiConnection",
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['outlook']['connectionId']"
                        }
                    },
                    "method": "post",
                    "body": {
                        "To": "@json(triggerBody())?['receipient']",
                        "Subject": "@json(triggerBody())?['title']",
                        "Body": "<p class=\"editor-paragraph\">@{json(triggerBody())?['message']}</p>",
                        "Importance": "Normal"
                    },
                    "path": "/v2/Mail"
                },
                "runAfter": {},
                "operationOptions": "DisableAutomaticDecompression"
            }
        },
        "outputs": {},
        "parameters": {
            "$connections": {
                "type": "Object",
                "defaultValue": {}
            }
        }
    },
    "parameters": {
        "$connections": {
            "type": "Object",
            "value": {
                "outlook": {
                    "id": "/subscriptions/xxxxxx/providers/Microsoft.Web/locations/australiaeast/managedApis/outlook",
                    "connectionId": "/subscriptions/xxxxxx/resourceGroups/logic-app-rg/providers/Microsoft.Web/connections/outlook",
                    "connectionName": "outlook",
                    "connectionProperties": {}
                }
            }
        }
    }
}

And when you click Run draft with payload. Hopefully you get to be able to run successfully.





Comments

Popular posts from this blog

gemini cli getting file not defined error

mongosh install properly

llama cpp running it in google colab