Audiences
Commands for managing audiences in the Knock CLI.
Audience commands enable you to manage audiences in your Knock account from the CLI.
Audience file structure
#When audiences are pulled from Knock, they are stored in directories named by their audience key. Each audience directory contains an audience.json file that describes the audience's configuration (name, type, and for dynamic audiences, segments).
audiences/ āāā new-signups/ āāā audience.json
If you're migrating your local audience 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 audience push --all.
knock audience list [flags]
#Display all audiences for an environment. Use an --environment flag to specify the target environment; if omitted, the Knock CLI defaults to the development environment.
Flags
The environment to use. Defaults to development.
The branch to use. Defaults to the main branch.
Should any uncommitted changes be hidden? Defaults to false.
The total number to fetch per page.
Fetches all entries after this cursor.
Fetches all entries before this cursor.
Format output as json.
knock audience get <audience_key> [flags]
#Display a single audience from an environment.
Use an --environment flag to specify the target environment; if omitted, the Knock CLI defaults to the development environment.
Flags
The environment to use. Defaults to development.
The branch to use. Defaults to the main branch.
Should any uncommitted changes be hidden? Defaults to false.
Format output as json.
knock audience pull <audience_key> [flags]
#Pull one or more audiences from an environment into a local file system. Knock CLI will create a new audience directory or update the existing audience directory in the local file system.
By default this command will resolve to the audiences 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 --audiences-dir flag.
Note: if pulling the target audience for the first time (or all audiences), Knock CLI will ask to confirm before writing to the local file system.
See the Audience file structure section for details on how audience files are organized.
Flags
The environment to use. Defaults to development.
The branch to use. Defaults to the main branch.
Whether to pull all audiences from the specified environment into the target directory path set by --audiences-dir. Defaults to false.
When used, all contents in the target directory will be erased and replaced with all audiences from the specified environment.
Specifies which target directory path to pull all audiences into. Only available to be used with --all, and defaults to the current working directory.
Should any uncommitted changes be hidden? Defaults to false.
Removes the confirmation prompt. Defaults to false.
knock audience push <audience_key> [flags]
#Push one or more audiences from a local file system to Knock. Knock will update an existing audience by the matching audience key, or create a new audience if it does not exist yet.
By default this command will resolve to the audiences 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 --audiences-dir flag.
Note:
- You must be directly above the target audience directory when running the
audience pushcommand, so the CLI can locate theaudience.jsonfile. - You can also pass in the
--commitflag (with an optional--commit-messageflag) to commit the upserted changes immediately. - Use
--forceto bypass environment restrictions and overwrite content in any environment. If you're using this on a non-development environment, you should also ensure you commit the changes.
See the Audience file structure section for details on how audience files are organized.
Flags
The environment to push the audience to. Defaults to development.
The branch to use. Defaults to the main branch.
Push and commit the audience(s) at the same time. Defaults to false.
The commit message to pass when using the --commit flag.
Whether to push all audiences from the target directory path set by --audiences-dir. Defaults to false.
Specifies the target directory path to find and push all audiences from. Only available to be used with --all, and defaults to the current working directory.
Force pushes the resource or resources to Knock, overwriting whatever is currently stored. If you're using this on a non-development environment, you should also ensure you commit the changes. Defaults to false.
knock audience validate <audience_key> [flags]
#Validate one or more audiences from a local file system. Knock will validate the given audience payload in the same way as it would with the audience push command, except without persisting those changes.
Note: Validating an audience is only done against the development environment.
Flags
Whether to validate all audiences from the target directory path set by --audiences-dir. Defaults to false.
Specifies the target directory path to find and validate all audiences from. Only available to be used with --all, and defaults to the current working directory.
knock audience archive <audience_key> [flags]
#Archive an audience across all environments. Archiving removes the audience from use but preserves its configuration.
Flags
The environment in which the audience exists.
The branch to use. Defaults to the main branch.
Removes the confirmation prompt. Defaults to false.