Summary
The Yext CLI lets you manage your account's Configuration as Code (CaC) resources from your local machine. Much of your Yext account's configuration is stored as a set of JSON configuration files. You can manage most of this configuration through the Yext platform UI, but the CLI lets you make fast, programmatic updates directly from your local machine.
This article walks through the core CLI workflow:
- Installing the CLI
- Logging in to your account
- Pulling your account's configuration files to your local machine
- Editing a file locally
- Applying your changes back to your account
Prerequisites
- A Yext account, either in a Sandbox or Production environment.
- A code editor, such as VS Code or Sublime Text
Install the Yext CLI
Full installation instructions for installing the CLI on Mac, Windows, and Linux are available in the CLI reference documentation.
Log in to Your Account
To connect the CLI to your account, run yext init.
- Run
yext init. If you're connecting to a sandbox account, include the-uor--universeflag:
yext init -u sandbox
If you're connecting to a production account, exclude the flag.
- When prompted, select Create new credentials if this is the first time you're connecting the CLI to this account.
- Enter your Yext Account ID. Find your Account ID in Account Settings > Personal Settings, in the Account Information table, or in your account's URL after
/s/. - Select the link to authenticate into your account.
If you get an authentication error, confirm you're using the correct -u flag for your account type.
Pull Your Account's Configuration
After you log in, pull your account's configuration files to your local machine:
yext resources pull ~/cli-guide
This command creates a new directory named cli-guide in your root directory. You can change the destination by editing the path in the command.
Open the directory in your file browser or code editor to view the files.
Make Changes Locally
Open a configuration file in your code editor and make a change. For example, you can:
- Edit the
yext/nameproperty in a file underdefault/km/entityto update an entity name - Add a new field definition in the
c/km/fielddirectory:
{
"$id": "c_myNewField",
"$schema": "https://schema.yext.com/config/km/field/v1",
"description": "",
"displayName": "My New Field",
"group": "NONE",
"localization": "PRIMARY_ONLY",
"type": {
"stringType": {
"stereotype": "SIMPLE"
}
},
"typeId": "yext/string"
}- Remove a folder, such as
default/pages, from your local directory. This doesn't delete anything from your account. It means those files are excluded from your next apply. Runyext resources pullagain if you want those files back on your local machine.
Save your changes before continuing.
Apply Your Changes
Push your local changes back to your account:
yext resources apply ~/cli-guide
If you pulled your resources into a different directory in the earlier step, use that directory path instead of cli-guide.
Expected result
The CLI applies your local changes to your Yext account's configuration. If the command returns an error, review the error message for the specific resource or field that failed.