Parsing CSV files in Azure Logic Apps

The Problem

I recently had the need in an Azure Logic App to read a CSV file from an Azure Storage account, parse the file, and then process the data row by row.

Unfortunately, there is no built-in action in Logic Apps to parse CSV files.

So as to avoid having to write an Azure function, or use a number of slow, low level Logic App actions, I decided to use the PowershellCode action to parse the CSV file quickly inline with the rest of the Logic App.

The documented code sample suggests the following should work

# Retrieve outputs from prior steps
$csvdata = Get-ActionOutput -ActionName FileContent

$rows = $csvdata | ConvertFrom-csv

# Push outputs forward to subsequent actions
Push-WorkflowOutput -Output $rows

However this resulted in a null value for $rows.

The Solution

The problem turned out to be that the getFileContentV2 action that I used to load the file from Azure storage, returned the file content as part of an object, not as a simple string. So I had to request the correct property from the object.

# Retrieve outputs from prior steps
$action = Get-ActionOutput -ActionName FileContent
$csvdata = $action.outputs['body'].ToString();

$rows = $csvdata | ConvertFrom-csv

# Push outputs forward to subsequent actions
Push-WorkflowOutput -Output $rows

Once this change was made, the CSV file was parsed correctly and I was able to process the data as required.

For the original version of this post see Richard Fennell's personal blog at Parsing CSV files in Azure Logic Apps