Docs
/
/

Goals

Commands for managing goals in the Knock CLI.

#

Goal commands enable you to manage goals in your Knock account from the CLI.

Goal file structure

#

When goals are pulled from Knock, they are stored in directories named by their goal key. Each goal directory contains a goal.json file that describes the goal's configuration (name, description, and condition).

If you're migrating your local goal files into Knock, you can arrange them using the example file structure above and then push them into Knock with a single command using knock goal push --all.

To attach a goal to a workflow, broadcast, or guide, set goal_attachment on that resource's JSON (goal_key and attribution_window_days). Attachments are not stored on the goal itself.

knock goal list [flags]

#

Display all goals for an environment. Use an --environment flag to specify the target environment; if omitted, the Knock CLI defaults to the development environment.

Flags

--environmentstring

The environment to use. Defaults to development.

--branchstring

The branch to use. Defaults to the main branch.

--limitnumber

The total number to fetch per page.

--afterstring

Fetches all entries after this cursor.

--beforestring

Fetches all entries before this cursor.

--jsonstring

Format output as json.

knock goal get <goal_key> [flags]

#

Display a single goal from an environment.

Use an --environment flag to specify the target environment; if omitted, the Knock CLI defaults to the development environment.

Flags

--environmentstring

The environment to use. Defaults to development.

--branchstring

The branch to use. Defaults to the main branch.

--jsonstring

Format output as json.

knock goal pull <goal_key> [flags]

#

Pull one or more goals from an environment into a local file system. Knock CLI will create a new goal directory or update the existing goal directory in the local file system.

By default this command will resolve to the goals resource directory via your knock.json file. When not set, will use the current working directory as the default. In the case of the --all flag, the target directory path will be resolved via your knock.json file or the --goals-dir flag.

Note: if pulling the target goal for the first time (or all goals), Knock CLI will ask to confirm before writing to the local file system.

See the Goal file structure section for details on how goal files are organized.

Flags

--environmentstring

The environment to use. Defaults to development.

--branchstring

The branch to use. Defaults to the main branch.

--allboolean

Whether to pull all goals from the specified environment into the target directory path set by --goals-dir. Defaults to false.

When used, all contents in the target directory will be erased and replaced with all goals from the specified environment.

--goals-dirdirectory

Specifies which target directory path to pull all goals into. Only available to be used with --all, and defaults to the current working directory.

--forceboolean

Removes the confirmation prompt. Defaults to false.

knock goal push <goal_key> [flags]

#

Push one or more goals from a local file system to Knock. Knock will update an existing goal by the matching goal key, or create a new goal if it does not exist yet. Goal upserts publish immediately; this command does not accept a --commit flag.

By default this command will resolve to the goals resource directory via your knock.json file. When not set, will use the current working directory as the default. In the case of the --all flag, the target directory path will be resolved via your knock.json file or the --goals-dir flag.

Note:

  • You must be directly above the target goal directory when running the goal push command, so the CLI can locate the goal.json file.
  • Use --force to bypass environment restrictions and overwrite content in any environment.

See the Goal file structure section for details on how goal files are organized.

Flags

--environmentstring

The environment to push the goal to. Defaults to development.

--branchstring

The branch to use. Defaults to the main branch.

--allboolean

Whether to push all goals from the target directory path set by --goals-dir. Defaults to false.

--goals-dirdirectory

Specifies the target directory path to find and push all goals from. Only available to be used with --all, and defaults to the current working directory.

--forceboolean

Force pushes the resource or resources to Knock, overwriting whatever is currently stored. Defaults to false.

knock goal validate <goal_key> [flags]

#

Validate one or more goals from a local file system. Knock will validate the given goal payload in the same way as it would with the goal push command, except without persisting those changes.

Flags

--environmentstring

The environment to validate the goal against. Defaults to development.

--branchstring

The branch to use. Defaults to the main branch.

--allboolean

Whether to validate all goals from the target directory path set by --goals-dir. Defaults to false.

--goals-dirdirectory

Specifies the target directory path to find and validate all goals from. Only available to be used with --all, and defaults to the current working directory.

knock goal new [flags]

#

Create a new goal with a minimal configuration. The command creates a new goal directory in your local file system. By default, this will be in the goals resource directory set by your knock.json file, or the current working directory if not configured.

Flags

--namestring

The name of the goal. If not provided, will be generated from the key.

--keystring

The key of the goal. If not provided, will be prompted or inferred from the directory name.

--descriptionstring

The description of the goal.

--environmentstring

The environment to create the goal in. Defaults to development.

--branchstring

The branch to use. Defaults to the main branch.

--pushboolean

Push the goal to Knock after creating it locally. Defaults to false.

--forceboolean

Force creation of the goal directory without confirmation. Defaults to false.

knock goal open <goal_key> [flags]

#

Open a goal in the Knock dashboard. This command opens the goal page in your default browser.

Flags

--environmentstring

The environment to use. Defaults to development.

--branchstring

The branch to use. Defaults to the main branch.

knock goal archive <goal_key> [flags]

#

Archive a goal. Archiving stops new completion and attribution calculation for the goal and cannot be undone. Historical versions and completions are retained.

Flags

--environmentstringRequired

The environment in which the goal exists.

--branchstring

The branch to use. Defaults to the main branch.

--forceboolean

Removes the confirmation prompt. Defaults to false.

knock goal clone <goal_key> [flags]

#

Clone a goal into a destination environment. Cloning copies the latest version of the goal (name, description, and condition). It does not copy attachments to workflows, broadcasts, or guides.

Flags

--environmentstringRequired

The environment that contains the source goal.

--destination-environmentstringRequired

The environment to clone the goal into.

--keystring

The key for the cloned goal. Defaults to the source key with a -copy suffix.

--namestring

The name for the cloned goal. Defaults to the source name with a (Copy) suffix.

--forceboolean

Removes the confirmation prompt. Defaults to false.

New chat