简体   繁体   中英

Mapping request body fields in logic apps

We have configured common alert schema for alerts and we are using a ticketing software and whenever we receive alert it should create a ticket.

In the logic app I have to make Post API call for creation of ticket with following json object, some fields are hard coded values:

{
    "subject": "",
    "Id": "123456789", // Hard code value
    "priority": "",
    "email": "test@test.com",   // Hard code value
    "status": "Open" // Hard code value
}

Parse Json sample payload schema for Alert:

{
    "data": {
        "alertContext": {
           
            },
            
        },
        "customProperties": null,
        "essentials": {
            "alertContextVersion": "123",
            "alertId": "123",
            "alertRule": "Test Alerts",
             "description": "test",
            "severity": "Sev4"        
        }
    },
    "schemaId": "test"
}

I have to map "subject and "priority" fields with alert json object "description" and "severity":

subject-->description
priority --> severity // sev0 =high ,sev1=medium, sev2 =low

How can I achieve this using logic app?

After Parse JSON You can directly map its objects in the compose connector with the required fields. Below is my logic app flow.

在此处输入图像描述

You can use the below Code view to reproduce the same in your Logic app

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": {
                    "customProperties": null,
                    "data": {
                        "alertContext": {}
                    },
                    "essentials": {
                        "alertContextVersion": "123",
                        "alertId": "123",
                        "alertRule": "Test Alerts",
                        "description": "test",
                        "severity": "Sev4"
                    },
                    "schemaId": "test"
                },
                "runAfter": {},
                "type": "Compose"
            },
            "Compose_2": {
                "inputs": {
                    "Id": "123456789",
                    "email": "test@test.com",
                    "priority": "@{body('Parse_JSON')?['essentials']?['severity']}",
                    "status": "Open",
                    "subject": "@{body('Parse_JSON')?['essentials']?['description']}"
                },
                "runAfter": {
                    "Parse_JSON": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "Parse_JSON": {
                "inputs": {
                    "content": "@outputs('Compose')",
                    "schema": {
                        "properties": {
                            "customProperties": {},
                            "data": {
                                "properties": {
                                    "alertContext": {
                                        "properties": {},
                                        "type": "object"
                                    }
                                },
                                "type": "object"
                            },
                            "essentials": {
                                "properties": {
                                    "alertContextVersion": {
                                        "type": "string"
                                    },
                                    "alertId": {
                                        "type": "string"
                                    },
                                    "alertRule": {
                                        "type": "string"
                                    },
                                    "description": {
                                        "type": "string"
                                    },
                                    "severity": {
                                        "type": "string"
                                    }
                                },
                                "type": "object"
                            },
                            "schemaId": {
                                "type": "string"
                            }
                        },
                        "type": "object"
                    }
                },
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "ParseJson"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {},
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM