Importing entries from the command line with WP-CLI
The wp gk import command runs a GravityImport import on the server, from a CSV file and an import profile saved in the WordPress admin. It returns when the import has finished, so a server script or a scheduled task can run imports without anyone opening the importer.
The command needs WP-CLI on the server and GravityImport 2.11.0 or later. With profiles saved in the import wizard, use 2.12.7 or later. Earlier versions stop with “Form structure has changed since profile was saved” for many forms that haven’t changed, such as forms with Checkbox, Multiple Choice, Time, or Date fields.
Save an import profile #
The command takes the column mapping from an import profile: a JSON file with the mapping and the import options from the importer’s Configure step.
To make one, import a file with the same columns in the WordPress admin, as described in Getting started with GravityImport. When the import finishes, click Download Import Profile on the Import Complete screen.

The same button is next to Continue With Import on the Map Fields and Configure steps. A profile saved at the end comes from an import you have seen work, so that is the one to keep.
Copy the profile to the server where you run WP-CLI. The same file also works in the browser: Load Import Profile on the Map Fields step applies it to an import there, as Mapping CSV columns to form fields describes.
Run an import #
From the folder with the files, pass the CSV file and the profile to wp gk import run:
wp gk import run --file=volunteers.csv --profile=volunteer-roster-profile.jsonWhen the import is done, the command prints a summary:
Creating import batch for Form #48...
Batch #271 created. Processing...
Status: done
Success: Import complete: 7 entries imported from 7 rows.File paths can be relative to the folder you run the command from, or absolute.
Add --user with a WordPress username, such as --user=admin, to record that user as the creator of the new entries. Without it, the entries have no creator, the same as entries submitted by a visitor who isn’t logged in.
When some rows fail, the command imports the rest and ends with a warning instead of the success line:
Warning: Import finished with errors: 1 imported, 0 skipped, 1 rows had errors out of 2 rows.That follows the profile’s Continue Processing If Errors Occur option, which is on by default. A profile saved with it turned off makes the command stop with an error at the failed row.
These options are available:
| Option | What it does |
|---|---|
--file | The CSV file to import. Required. |
--profile | The import profile. Required. |
--user | The WordPress user recorded as the creator of the new entries. |
--form-id | Imports into this form instead of the one the profile was saved for, such as a copy made with Duplicate in the Gravity Forms forms list. |
--dry-run | Runs the checks and prints a summary without importing anything. |
--force | Imports even when the form has changed since the profile was saved. |
--format | The output format: table (the default), json, csv, or yaml. |
Check a profile before a run #
wp gk import validate takes the same --file and --profile and checks them without importing anything:
wp gk import validate --file=volunteers.csv \
--profile=volunteer-roster-profile.jsonProfile structure is valid.
Form #48 exists: Volunteer Roster
Form structure matches profile.
Column matching: 5 matched, 0 unmatched.
5 schema rules mapped successfully.
Success: Profile validation complete.The output confirms that the profile can be read, that the form exists and still matches the profile, and how many of the profile’s columns were found in the file. Run it before the first scheduled import, and again whenever the file or the form changes.
How the columns are matched #
The command matches the file’s columns to the profile by their header names, so the columns can come in a different order from the file the profile was saved with. The match ignores capital letters and spaces at either end of a header.
When a header isn’t found, the command uses the column in the same position as in the original file, unless another header already matched that column. A profile column with no match is left out. The run warns about it, and that field stays empty on the new entries:
Warning: 1 profile column(s) could not be matched to the CSV.When the form changes #
A profile also records the form’s fields as they were when it was saved. The form counts as changed when, since then, a field has been:
- added or deleted
- changed to another field type
- made required, or no longer required
- given another choice, on a Checkbox field
These changes don’t count:
- editing a field’s label
- moving a field on the form
- editing a Drop Down field’s choices
- renaming a Checkbox choice
- changing the format of a Date, Time, or Phone field
- changing a Date field’s Date Input Type
After a change, run stops before it imports anything, and so does run --dry-run:
Error: Form structure has changed since profile was saved. Use --force to proceed anyway.validate reports the same change as a warning and finishes its checks. It also warns about each mapped field that was deleted or has a different type:
Warning: The "Department" column (CSV column 3) is mapped to the "Department" field (field ID 3), which was a select field when the profile was saved and is now a radio field. Check that the column still fits the field, or map it again in the import wizard and save a new profile.
Warning: Form structure has changed since profile was saved.To bring the profile up to date, import a file in the WordPress admin again and download a new profile. --force runs the import with the old profile instead.
Warning: With --force, columns mapped to deleted fields are skipped, and every other column goes into the field the old mapping names. Read the warnings from validate before you use it.
Dates split across columns #
A profile saved with GravityImport 2.12.6 or earlier can map columns to the month, day, or year of a Date field. Such a profile stops both run and validate, because Gravity Forms saves one whole date on the field:
Error: The "Start date (MM)" column (CSV column 3) is mapped to the MM part (input 4.1) of the "Start date" Date field, but Gravity Forms saves one whole date on that field, so the column would not be imported. Map a column that holds the whole date to the "Start date" field (field ID 4) instead.Combine the parts into one date column, map it to the Date field in the import wizard, and download a new profile. With --format=json, the record’s code is gravityview/import/errors/date_input_rule and the exit status is 1.
Use the command in a script #
With --format=json, run and validate print one JSON record instead of the lines above:
wp gk import run --file=volunteers.csv \
--profile=volunteer-roster-profile.json --format=json[{"batch_id":278,"status":"done","total":2,"imported":1,"skipped":0,"errors":1,"last_error":""}]An import where some rows failed still exits with status 0, so a script should read errors from the record. The exit status is 1 when the command stops, such as for a missing file or a changed form. The record then has "status":"error", a code and a message:
[{"status":"error","code":"csv_not_found","message":"CSV file not found or not readable: volunteers-new.csv"}]