azure-logic-apps

Add extra attribute to object Logic app


Im trying to add an extra attribute to the respons object in logic app. I got 2 shape that sending request to two different http. In the third shape i want to merge the body from one respons with the other respons. Like below

"ResponsBody":{ "title": "", "created": "", "priority": "", "Category": "", "summary": "" }

So want i want take the ID from one of respons and merge it with the other one.

{ "ID":"" "title": "", "created": "", "priority": "", "Category": "", "summary": "" }

So far this is what i get. 23123{"title": "","created": "","priority": "","Category": "","summary":""} the ID is outside.

Code in Logic app: "body": "@{triggerBody()?['ID']}@{body('Get_HTTP_Info')?['data']}"


Solution

  • You can use the @union function to merge two objects

    "body": "@union(triggerBody(), body('Get_HTTP_Info'))"
    

    To add specific properties only, you can first use a compose action to prepare the content

    "compose1": {
      "type": "compose"
      "inputs": { "id": "@triggerBody()['Id']"}
    }
    

    And then you can do

    "body": "@union(outputs('compose1'), body('Get_HTTP_Info'))"