Skip to content
v2.7

Import and export data with the CLI

owbase data: import CSV and Excel, export a table, track, cancel, resume, and undo tasks, with the exit codes for scripts and CI.

The owbase data group does on the command line what the console does in Import and export: it imports a CSV or Excel (.xlsx) file into a table, exports a table, and manages the task history. It is the same service as the console and the import and export API: the analysis reads the whole file before writing, the conversion rules and limits are the same, and what the CLI creates shows up in the console history.

CLI messages are in English, like the rest of the CLI; API errors arrive as the API returns them.

  • On your machine: the owbase login session (Log in). The account must be able to create API keys in the project, because the task runs with a temporary key.
  • In CI and scripts: the OWBASE_API_KEY variable, which overrides the session (CI with an API key). The key needs the scopes in the table below, including keys.write.
  • Project: --project-id <id> or the projectId in the folder’s owbase.json.

API key scopes (every command also requires tables.read):

Command Scopes
import, export tables.read, rows.read, keys.write; import also needs rows.write
undo tables.read, rows.read, rows.write, keys.write
resume those of the task, plus keys.write
cancel tables.read, rows.write
tasks, task, download tables.read, rows.read
Terminal window
owbase data import customers.csv --database-id store --table-id customers

The command does, in order:

  1. uploads the file in 5 MiB parts, with progress;
  2. analyzes the whole file, writing nothing, and shows the summary;
  3. asks for your confirmation (--yes skips it);
  4. imports, with progress;
  5. shows the report and downloads the rejected rows, if there are any.

The analysis summary shows the rows read, valid, and with errors; the errors by type and by column, with up to 5 examples of each; how many rows would be created, updated, and skipped; the relation values that don’t exist (count and 5 examples per relation); the warnings; the file columns that were ignored; and the mapping used (file column → table column).

With nothing else, the mapping is automatic: Owbase matches the file columns to the table columns by name. It accepts .csv, .txt, .tsv, and .xlsx.

Terminal window
owbase data import customers.csv --database-id store --table-id customers --analyze-only

Stops after the summary and exits with code 0. Nothing is written. Use it to check the file before importing.

Terminal window
owbase data import customers.csv --database-id store --table-id customers --mapping "ERP customers"

--mapping uses a mapping that you saved in the console for the table, by name. If the name doesn’t exist or is ambiguous, the command stops with an error that lists the table’s mappings.

Terminal window
owbase data import customers.csv --database-id store --table-id customers --config import.json

--config reads a JSON file with the import configuration (columns, conversion rules, mode, keys), without the arquivoId field: the CLI fills it in with the file it just uploaded. It is the way to use settings that the command line doesn’t cover, and to version the configuration along with the code.

--mapping and --config don’t go together: use one or the other.

These options apply on top of the automatic suggestion, the saved mapping, or --config:

Option What it does
--mode create|update|upsert Only create, only update, or create or update (criar, atualizar, criar_ou_atualizar).
--key col[,col] Key columns used to find the row (in update and upsert modes).
--key-case ignore|exact Match keys ignoring uppercase and lowercase, or exactly (default).
--fast Fast update (writes the updates in batches; see the caveats in Mode).
--empty keep|clear An empty cell keeps the current value (default) or clears it.
--on-error skip|stop A row with an error: skip it (default; it goes to the rejected rows) or stop at the first error.
--timezone <IANA> Time zone for dates without a time zone, such as America/Sao_Paulo.
--sheet <name> The sheet to read, in an .xlsx file.
--delimiter <c> CSV delimiter (detected by default).
--encoding <name> File encoding (detected by default).

When the file has, in a relation column, values that don’t exist in the related table, the CLI needs a decision for each column:

Terminal window
owbase data import orders.csv --database-id store --table-id orders \
--missing customer=skip
Decision What happens
--missing <column>=create Creates the missing records in the related table.
--missing <column>=skip Skips the rows with those values (they go to the rejected rows, with the reason).
--missing <column>=empty Imports the row with the relation empty.

The option repeats, once per column. Without a decision for a column with missing values:

  • in an interactive terminal, the CLI asks;
  • without a terminal (script, CI), it stops with an error, code 1, listing the --missing options that are missing. Nothing is imported.

create works directly when the related table has no required columns besides the matching field. If it does, the values of those columns go in through --config, in the decisoes field of the JSON (the same shape as the decisoes field of the import through the API):

{
"decisoes": { "customer": { "acao": "criar", "valoresFixos": { "name": "No name" } } }
}
Option What it does
--yes Asks nothing. Also authorizes overwriting the rejected-rows file, if it already exists.
--no-wait Exits after creating the import and prints the task ID; track it with owbase data task <id>.
--rejected <path> Where to save the rejected rows. Default: the name of the uploaded file without the extension + .rejected.csv (or .rejected.xlsx for a spreadsheet), next to it (customers.csv → customers.rejected.csv). Never overwrites without --yes.
--json JSON output (the summary and the final task), for scripts.

The rejected-rows file is the same as the console’s Download rejected rows: the original columns plus erro_linha and erro_motivo (error_line and error_reason when the environment isn’t in Portuguese: the CLI picks the language from LC_ALL, LC_MESSAGES or LANG). Fix it and import again (how it works).

The CLI polls the task every 1.5 seconds, like the console. In a terminal, it shows a line that rewrites itself with the phase, the rows done out of the total, the rows per second, and the time remaining. Without a terminal, it prints a line every 10 seconds.

Code Meaning
0 Completed and all the rows read went into the table (or --analyze-only finished)
3 Completed, but some row didn’t go in: a row with an error, a row skipped by the --missing <column>=skip decision, or a key that found no row in update mode. Those rows go to the rejected-rows file
1 Failed, was canceled, or the command was used incorrectly (for example, a --missing decision is missing and there is no terminal)
130 Interrupted by Ctrl-C

On 130, the task keeps running on the server: the CLI prints how to track it (owbase data task <id>) and how to cancel it (owbase data cancel <id>).

In a script, treat 3 as “imported, but check the rejected rows”:

Terminal window
owbase data import customers.csv --database-id store --table-id customers --yes
case $? in
0) echo "everything imported" ;;
3) echo "imported with rejected rows: see customers.rejected.csv" ;;
*) echo "the import did not finish" >&2; exit 1 ;;
esac

In CI there is no login or terminal: use OWBASE_API_KEY, --yes, and a --missing decision for each relation that may have missing values.

- name: import customers
env:
OWBASE_API_KEY: ${{ secrets.OWBASE_API_KEY }}
run: |
npm i -g @owbase/cli@1
owbase data import data/customers.csv \
--project-id <PROJECT_ID> \
--database-id store --table-id customers \
--mode upsert --key email --yes

The key needs the import scopes from the table above (including keys.write). The step fails with 1 if the import doesn’t finish and with 3 if there are rejected rows; to accept rejected rows, handle the code as in the previous example. The rejected rows end up in data/customers.rejected.csv: publish them as a job artifact.

Terminal window
owbase data export --database-id store --table-id customers

Creates the export, waits for it to finish, and downloads the file. By default it writes <table>.<ext> in the current folder.

Option What it does
--format csv|xlsx File format. Default: from the extension of --output; without it, csv.
--columns a,b,$id The columns and their order. $id, $createdAt, and $updatedAt are also valid. Without the option, exports all of them.
--relation <column>=<field> Which field of the related table goes in the file, per relation column (default: $id). Repeatable.
--delimiter <c> CSV delimiter.
--output <path> Where to save. Never overwrites an existing file without --yes.
--no-wait Exits after creating the export and prints the ID; download later with owbase data download.
Terminal window
owbase data export --database-id store --table-id orders \
--columns '$id,code,customer,amount' --relation customer=email \
--output orders.xlsx

The CSV comes out in the console format (UTF-8 with BOM, ready for Excel), and text that would start with =, +, -, or @ gets a ' in front, so the spreadsheet doesn’t execute it (Export). The limit is 500,000 rows per export.

Terminal window
owbase data tasks # the project's tasks
owbase data tasks --database-id store --table-id customers --limit 5
owbase data task <id> # the full report of a task

tasks lists ID, type, table, state, counters, and when it happened. It filters by --database-id and --table-id, by --type (import, export, analysis, or undo), and limits with --limit N. task <id> shows the full report.

Terminal window
owbase data cancel <id> # stops after the current chunk; what was already written stays
owbase data resume <id> # continues from the point where the task stopped

See Cancel and resume to know when each one applies.

Terminal window
owbase data undo <id>

Before undoing, the CLI shows how many rows would be undone (deleted and restored) and asks for confirmation; --yes skips the question. The rules are those in Undo an import: up to 7 days after it ends, once per import, and rows changed afterward stay as they are. The undo is a task of its own, with progress and a report.

Terminal window
owbase data download <id> --file rejected # the rejected rows
owbase data download <id> --file missing --column customer
owbase data download <id> --file output --output orders.csv
--file The file
rejected The rejected rows of an import, with erro_linha and erro_motivo (or error_line and error_reason, depending on the language).
missing The relation values that don’t exist; use --column to name the column.
output The file generated by an export.
undo-skipped The rows that the undo didn’t touch.

The CLI asks the service for a signed link and downloads through it; each link is valid for 24 hours. --output chooses the file path.

Was this page helpful?