Knock CLI
Learn how to use the Knock CLI to build, test, and manage your Knock notification system from the terminal.
The Knock CLI helps you build, test, and manage your Knock notification system, right from the terminal. You can use the CLI to:
- Pull Knock workflows down to your local machine and work with your notification logic and templates in your code editor.
- Integrate Knock into your CI/CD pipeline and automatically promote changes between Knock environments on release.
- Map your translation files into Knock to localize your notifications.
Installing the CLI#
You can install the Knock CLI using npm
, a node package manager, with the following command:
Once the CLI is installed, you can call it by using the knock
command in your terminal. The CLI is also available via Homebrew for macOS. See the installation documentation.
Authenticating the CLI#
Using your Knock account#
You can authenticate your Knock account against the CLI by running knock login
. This will open a browser window where you can sign in to your Knock account and authorize the CLI to access your account.
Once authenticated, you can verify it works by running knock whoami
. If your account is valid and configured properly, you'll receive a 200 response that shows the account name and your user ID.
If you need to switch between accounts, you can run knock logout
to log out of your current account and log in to a different one.
Using a service token#
If you need to authenticate in a remote environment, or want complete control, you can generate a service token in the Knock dashboard.
Once you have generated a service token, you can verify it works by running knock whoami --service-token=YOUR_SERVICE_TOKEN
. If your token is valid and configured properly, you'll receive a 200 response that shows the account name and the service token name.
CLI reference#
You can find a complete reference for all of the commands and flags available on the CLI in our comprehensive reference.