Search code examples
azureazure-logic-appspower-automate

Creating CSV table from Crowdstrike API output


I am having an issue parsing JSON from the Crowdstrike API in the logic app. I am making an HTTP call to CS to get all device IDs.

In the resources part of the JSON it returns 2574 device IDs in the API call indicating all of our hosts. I then have to make another API call to the CS API to get the hostname from the device ID, I then want to create a CSV from all of the hostnames.

Here is the Logic app with all steps: Logic App 1 Logic App 2

When running the logic app I can see it is running through each of the 2574 device IDs successfully and for each one is creating a CSV successfully with the following output: Logic App Run History

My question is, is it creating one big CSV with all of the hostnames or is it creating a new CSV with each hostname?

The goal of this logic app is to have a table of the CS hosts and compare it to a lists of hosts from Azure Arc and see if there is any host in Azure Arc that is not managed in CS.

Can anyone help guide me on this? I am stuck.


Solution

  • Your logic is creating a new table for every instance of device.

    What you need to do is to use a string variable to build your CSV data.

    Before your loop, create an Initialize variable action. If you want a header row in your CSV, set it here. For example:

    "deviceID,hostName,operating operatingSystem,version\n"

    The \n will indicate a new line.

    Then, inside your for loop at the end (after you have retrieved hostname and other info), add an "Append to string variable" action. Configure the value to use the required task output values from the previous API call.

    Finally, add a HTTP response action, after the loop. Set the headers as follows:

    {
      "Content-Type": "text/csv",
      "Content-Disposition": "attachment; filename=output.csv"
    }
    

    Set body to @{variables('csvContent')}, or whatever you named your variable.