'Insert parameters into JSON Array in Logic Apps

I am creating a Logic app to gather members from one platform using an API call and posting them to another platform using POST method. At the end of the entire process, I get a JSON array with the data that I need. However, I need to add in a parameters into the array at the beginning. How would I go about doing so?

Currently, my array looks like this

[
  {
    "company": "",
    "email": "",
    "firstName": "",
    "lastName": "",
    "nickname": "",
    "prefix": "",
    "sourceId": "",
    "title": "",
    "workPhone": ""
  },
  {
    "company": "",
    "email": "",
    "firstName": "",
    "lastName": "",
    "nickname": "",
    "prefix": "",
    "sourceId": "",
    "title": "",
    "workPhone": ""
  }
]

I need for the body of my HTTP request to look like this:

**{"data":**
    [
     **"dataRecord":** {
        "company": "",
        "email": "",
        "firstName": "",
        "lastName": "",
        "nickname": "",
        "prefix": "",
        "sourceId": "",
        "title": "",
        "workPhone": ""
      },
      {
        "company": "",
        "email": "",
        "firstName": "",
        "lastName": "",
        "nickname": "",
        "prefix": "",
        "sourceId": "",
        "title": "",
        "workPhone": ""
      }
    }

My current flow looks like this:

  • Scheduled Trigger

  • List item

  • Authenticate platform (to)

  • Authentication platform(from)

  • Get Data

  • Compose data

  • Parse Json

  • Initialize Array Variable

  • For Each: (1)Compose - Map Parsed JSON data to Destination Fields (2)Append to array variable

  • compose expression: string(variables('variable'))

  • Compose string to Json: json(string(outputs('Compose_2')))

  • HTTP POST

Edit: Adding screenshot of where I need the data to be in the output, along with what my app looks like

JSON Output after for each

App layout



Solution 1:[1]

After receiving the json array try using Parse Json action of Data Operations Connector to get the parameters and then you can form a json using Compose Connector. Here is the screenshot of my logic app for your reference.

enter image description here

Here is the output:

enter image description here

enter image description here

Here is the schema in the compose connector

{
  "data": [
    {
      "dataRecord": {
        "company": "@{items('For_each')['company']}",
        "email": "@{items('For_each')['email']}",
        "firstName": "@{items('For_each')['firstName']}",
        "lastName": "@{items('For_each')['lastName']}",
        "nickname": "@{items('For_each')['nickname']}",
        "prefix": "@{items('For_each')['prefix']}",
        "sourceId": "@{items('For_each')['sourceId']}",
        "title": "@{items('For_each')['title']}",
        "workPhone": "@{items('For_each')['workPhone']}"
      }
    }
  ]
}

Below is the code view of my logic app

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_each": {
                "actions": {
                    "Compose": {
                        "inputs": {
                            "data": [
                                {
                                    "dataRecord": {
                                        "company": "@{items('For_each')['company']}",
                                        "email": "@{items('For_each')['email']}",
                                        "firstName": "@{items('For_each')['firstName']}",
                                        "lastName": "@{items('For_each')['lastName']}",
                                        "nickname": "@{items('For_each')['nickname']}",
                                        "prefix": "@{items('For_each')['prefix']}",
                                        "sourceId": "@{items('For_each')['sourceId']}",
                                        "title": "@{items('For_each')['title']}",
                                        "workPhone": "@{items('For_each')['workPhone']}"
                                    }
                                }
                            ]
                        },
                        "runAfter": {},
                        "type": "Compose"
                    }
                },
                "foreach": "@body('Parse_JSON')",
                "runAfter": {
                    "Parse_JSON": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Parse_JSON": {
                "inputs": {
                    "content": "@triggerBody()",
                    "schema": {
                        "items": {
                            "properties": {
                                "company": {
                                    "type": "string"
                                },
                                "email": {
                                    "type": "string"
                                },
                                "firstName": {
                                    "type": "string"
                                },
                                "lastName": {
                                    "type": "string"
                                },
                                "nickname": {
                                    "type": "string"
                                },
                                "prefix": {
                                    "type": "string"
                                },
                                "sourceId": {
                                    "type": "string"
                                },
                                "title": {
                                    "type": "string"
                                },
                                "workPhone": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "company",
                                "email",
                                "firstName",
                                "lastName",
                                "nickname",
                                "prefix",
                                "sourceId",
                                "title",
                                "workPhone"
                            ],
                            "type": "object"
                        },
                        "type": "array"
                    }
                },
                "runAfter": {},
                "type": "ParseJson"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SwethaKandikonda-MT