Skip to content

Export data

A to… verb sends data out of a node. The rows pass through it unchanged, so an export can sit in the middle of a node file and statements after it keep working on the same rows.

Verb Sends
toFile(path) A Workspace file in the format its extension names
toEmail(recipient) An email, optionally with the rows attached
toApi(url) The rows to a REST API
toGraphql(url, mutation) The rows through a GraphQL mutation

A subject in front of the verb chooses what it sends:

Written as Sends
toFile("out.csv") The current rows, as they stand at that statement
input().toFile("raw.csv") The rows the node received, before its statements changed them
inputs("prices").toFile("prices.csv") One named table
context().toFile("summary.json") The formula’s context values
eachRow().toEmail(…), eachRow().toApi(…) One email or call per row

toFile(path) writes a Workspace file, with the path relative to the node file. The extension picks the format:

Extension Format
.csv, .tsv, .psv Comma, tab, or pipe-separated text
.xlsx, .xls Excel workbook
.json JSON
.xml XML
.txt Text
.fix FIX messages, with recomputed checksum fields
toFile("../out/positions.xlsx")
toFile("../out/positions.csv")

.format(id) sets the format when the file name has no usable extension, such as toFile("../out/feed.dat").format("csv"). An unknown extension without .format is an error in the editor. SWIFT files load but have no writer.

  • The path is a literal; the editor checks it before the run.
  • One node file never reads and writes the same path. To update a file, read it in one node and write it in a node downstream.
  • A dotted column name such as bond.isin nests in JSON output and stays a dotted header in CSV.
  • After a run, the node’s canvas strip links to the file it wrote, and opening the file shows it in the same Explore view as the node’s rows.

See Egress for FIX round trips and file exports in detail.

toEmail("finance@acme.example.com")
.subject("Overdue invoices")
.body("The overdue invoices are attached.")
.format("xlsx")

.format("csv" | "tsv" | "xlsx" | "json") attaches the rows as a file; .attach(path, …) attaches Workspace files, including one the same node wrote earlier with toFile. With eachRow(), the recipient, subject, and body can read the row. Email leaves as an agent, whose send whitelist must match every recipient. See Send and receive email.

eachRow().toApi("https://api.example.com/orders")
.method("POST")
.send("order_id", "customer", "total")
.returns("id", "number")

.send(name, …) names the columns that make the JSON body. Per row, the answer’s fields can come back as columns with .returns. Without eachRow(), the rows go out as one JSON list, split into requests of .batch(n) rows. toGraphql takes the same options with a mutation. See Call REST and GraphQL APIs.

A per-row send that fails records the reason on that row and the other rows still send. A send for the whole table that fails fails the node.

A node that writes a file or sends an email starts with this trigger condition:

input().exceptions().prop("warning") == 0 and input().exceptions().prop("error") == 0

The node runs only when no node upstream raised a warning (severity 3) or an error (severity 4 or 5) in that build. input().exceptions() counts every exception raised upstream of the node, through every wire, so a check several nodes back holds the export too. Info exceptions (severity 1 or 2) let it run.

Edit the condition on the node to change the rule, for example to allow warnings:

input().exceptions().prop("error") == 0

or set it to always to export whatever arrives. A condition reads one wire’s upstream with inputs().prop("prices").exceptions(). exceptions() belongs to a node’s trigger condition; in a formula statement it fails with a message saying so. See How a node runs.