0

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

1 Answer 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": {}
}
Sign up to request clarification or add additional context in comments.

10 Comments

Thank you for the response. If I add those items in the For Each compose, I will then have those data and Datarecord items repeated each time.
I added images to my original post with some images.
@Basilio The for each loop in here will point to the next array present in the input of parse json. so to not repeat the items each time you just need to write the json for one array. If you use the one that you have mentioned in the question you would probably receive duplicates. Can you try using the one which I have mentioned in the answer.
Understood! Thank you, let me try that.
I have used expressions to take the output of the Array variable and convert it to string. I then use the replace expression to add in the items that I need. However, Microsoft keeps adding in the escape \slashes. I can then use the Json conversion function to convert it back to json, but it removes the data I have added. @swethakandikonda-mt "{\"data\": [ \"dataRecord\":{\"company\":\"...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.