Loop Over a CSV

View as Markdown

When you have a CSV file and want to do something for every row in it, such as adding each row as a contact or looking each one up, the pattern is always the same: parse the file into rows, then loop over those rows.

Nodes involved

  • Parse CSV turns a .csv file into a list of rows.
  • For Each runs a set of steps once for every row.

How to build it

1

Parse the file

Add a Parse CSV step and point its CSV file field at the file you want to read. Turn the “first row is a header” option on so each column can be read by its name.

2

Loop over the rows

Add a For Each step and set its Collection to the parsed rows:

parse-csv.data.rows
3

Read each row inside the loop

Inside the loop, the current row is available as _each_.item. Read a column by its header name:

_each_.item.email

Add whatever steps you need inside the loop and point their fields at the columns you care about.

For Each has a “collect results” option. Leave it off for large files; a long list of gathered results can grow fast, and every pass is visible in the run history regardless.