0

I'm trying to send an email via Logic App. The content must be an array of an orphaned resources.

I am using an HTTP request to query the Azure resource graph explorer, on the Output I have a JSON object. I want to transform this JSON Object on an array.

enter image description here How to get an array from the output of HTTP POST request?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Makina74
  • 45
  • 6
  • Do you want the content of the "data" object to be pasted as the body into your email? – Skin Jan 18 '22 at 11:22
  • Yes , I want on the body of email, a array of data , now I just have json format which are paste without space and its unreadle. – Makina74 Jan 18 '22 at 12:17
  • Can you post the JSON into the question so we can use it to answer your question? – Skin Jan 18 '22 at 12:21

3 Answers3

1

Here is how it worked for me:

Taking provided JSON into consideration Instead of having body as From data in Create HTML table I have used data since the Create HTML table takes only array as input and then modified the same while sending the email.

Here is my Logic app : enter image description here

Here is the email : enter image description here

Updated Answer

Here is the whole logic app

enter image description here

For parse JSON I'm generating the schema using sample payload with the same JSON that you have provided with sample values. i.e..

{
  "body": {
    "totalRecords": 25,
    "count": 25,
    "data": [
      {
        "id": "SampleId",
        "diskState": "Sample",
        "resourceGroup": "dkfdfjsi",
        "location": "gareg",
        "subscriptionId": "fgser"
      },
      {
        "id": "SampleID2",
        "diskState": "SAmple2",
        "resourceGroup": "dkfdfjsi",
        "location": "gareg",
        "subscriptionId": "fgser"
      }
    ]
  }
}

As your requirement is to send the data in a tabular format I have used the same connector as you did i.e. Create HTML Table with data array as input to the connector and so it will be generating the table automatically with the headers in the format mentioned below

enter image description here

Lastly, I have used the output of the HTML Table connector to send the email

enter image description here

Here 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": {
           "Create_HTML_table_2": {
               "inputs": {
                   "format": "HTML",
                   "from": "@body('Parse_JSON')?['body']?['data']"
               },
               "runAfter": {
                   "Parse_JSON": [
                       "Succeeded"
                   ]
               },
               "type": "Table"
           },
           "Parse_JSON": {
               "inputs": {
                   "content": "@triggerBody()",
                   "schema": {
                       "properties": {
                           "body": {
                               "properties": {
                                   "count": {
                                       "type": "integer"
                                   },
                                   "data": {
                                       "items": {
                                           "properties": {
                                               "diskState": {
                                                   "type": "string"
                                               },
                                               "id": {
                                                   "type": "string"
                                               },
                                               "location": {
                                                   "type": "string"
                                               },
                                               "resourceGroup": {
                                                   "type": "string"
                                               },
                                               "subscriptionId": {
                                                   "type": "string"
                                               }
                                           },
                                           "required": [
                                               "id",
                                               "diskState",
                                               "resourceGroup",
                                               "location",
                                               "subscriptionId"
                                           ],
                                           "type": "object"
                                       },
                                       "type": "array"
                                   },
                                   "totalRecords": {
                                       "type": "integer"
                                   }
                               },
                               "type": "object"
                           }
                       },
                       "type": "object"
                   }
               },
               "runAfter": {},
               "type": "ParseJson"
           },
           "Send_an_email_(V2)_2": {
               "inputs": {
                   "body": {
                       "Body": "<p><strong>Total Records</strong> :@{body('Parse_JSON')?['body']?['totalRecords']} , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Count </strong>: @{body('Parse_JSON')?['body']?['count']}<br>\n-----------------------------------------------------------------------------<br>\n@{body('Create_HTML_table_2')}</p>",
                       "Subject": "Sample Test",
                       "To": "<YOUR REQUIRED EMAIL ID>"
                   },
                   "host": {
                       "connection": {
                           "name": "@parameters('$connections')['office365']['connectionId']"
                       }
                   },
                   "method": "post",
                   "path": "/v2/Mail"
               },
               "runAfter": {
                   "Create_HTML_table_2": [
                       "Succeeded"
                   ]
               },
               "type": "ApiConnection"
           }
       },
       "contentVersion": "1.0.0.0",
       "outputs": {},
       "parameters": {
           "$connections": {
               "defaultValue": {},
               "type": "Object"
           }
       },
       "triggers": {
           "manual": {
               "inputs": {},
               "kind": "Http",
               "type": "Request"
           }
       }
   },
   "parameters": {
       "$connections": {
           "value": {
               "office365": {
                   "connectionId": "/subscriptions/<YOUR SUBSCRIPTION ID>/resourceGroups/<YOUR RESOURCE GROUP>/providers/Microsoft.Web/connections/office365",
                   "connectionName": "office365",
                   "id": "/subscriptions/<YOUR SUBSCRIPTION ID>/providers/Microsoft.Web/locations/northcentralus/managedApis/office365"
               }
           }
       }
   }
}
SwethaKandikonda
  • 7,513
  • 2
  • 4
  • 18
0

You can use a specific schema in the parse JSON action to have it be parsed into (an array of) objects, if that structure is known.

To reference or access properties in JavaScript Object Notation (JSON) content, you can create user-friendly fields or tokens for those properties by using the Parse JSON action. That way, you can select those properties from the dynamic content list when you specify inputs for your logic app. For this action, you can either provide a JSON schema or generate a JSON schema from your sample JSON content or payload.

The article Perform data operations in Azure Logic Apps shows examples of exactly what you're trying to achieve, looking at your screenshot.

rickvdbosch
  • 14,105
  • 2
  • 40
  • 53
0

@SwethaKandikonda-MT enter image description here

I use recurence as trigger. After I use http connector to querying Azure resource graph to obtain the result of kql request. after the http i have a result in json object. I use as you , a Parse Json with the same schema. I create after a html table with data from the parse Json but when i run the loguc app , it makes an error because the from of html table is considered as null

Makina74
  • 45
  • 6