HubSpot CLI commands
The HubSpot CLI connects your local development tools to HubSpot, allowing you to develop on the HubSpot CMS with version control, your favorite text editor, and various web development technologies.
If you're new to developing on HubSpot, check out our quick start guide where you'll walk through installing the CLI all the way to publishing a live page.
Use this guide as a reference for the available commands and file formatting options for HubSpot's local development tooling. For a walkthrough of how to use these tools, see the getting started with local development tutorial.
You can install HubSpot local development tools either globally (recommended) or locally. To install the HubSpot tools globally, in your command line run the command below. Learn more about installing packages globally or locally.
To install the tools only in your current directory instead, run the command below. You do not need to install locally if you already have the CLI installed globally.
Getting an EACCES error when installing?
See NPM Resolving EACCESS permissions errors when installing packages globally.
The CLI is updated regularly. To upgrade to the latest version of the local tools, run:
The CLI changed from @hubspot/cms-cli
to @hubspot/cli
. If you are still using the old cms-cli you will need to uninstall it prior to installing the new version.
To see which version you're on, run:
hs --version
If your version number is less than 3.0.0, you're on the old version.
To uninstall the old version run:
npm uninstall -g @hubspot/cms-cli
Show all commands.
To learn more about a specific command, enter the command and --help
.
Creates your hubspot.config.yml
file in the current directory and sets up authentication for an account. If you're adding authentication for a new account to an existing config file, run the auth command. When prompted for a name to use for the account, the name can't contain spaces.
Generate authentication for a HubSpot account using a personal CMS access key. You can generate your access key here. If you already have a hubspot.config.yml
file you can use this command to add credentials for additional accounts. For example you might use your sandbox account as a development environment. When prompted for a name to use for the account, the name can't contain spaces.
Lists the name, ID, and auth type for the each account in your config file. If you're not seeing the accounts you expect, you may need to run the auth command to add accounts to your config file.
Set the default account in your config file.
Parameter | Description |
---|---|
accountNameOrID
| Identify the new default account by its name (as set in the config file) or ID |
Using the CLI, you can interact with the developer file system, which is the file system in the Design Manager.
List files stored in the developer file system by path or from the root. Works similar to using standard ls
to view your current directory on your computer.
Argument | Description |
---|---|
dest
Optional
| Path to the remote developer file system directory you would like to list files for. If omitted, defaults to the account root. |
Fetch a file, or directory and its child folders and files by path.
This takes files from your HubSpot account and brings them into your local environment. The <src> should be the path from your HubSpot Design tools. The <dest> is the local directory where you'd like to add these files.
As a precaution fetching does not by default overwrite your existing local files, you can use --overwrite
when you want to do that.
Argument | Description |
---|---|
src
Required
| Path in HubSpot Design Tools |
dest
Optional
| Path to the local directory you would like the files to be placed, relative to your current working directory. If omitted, this argument will default to your current working directory. |
Options | Description |
---|---|
--account
| Specify an Supports an alias of |
--overwrite
| Overwrite existing files with fetched files. |
--mode
| Specify if fetching a draft or published version of a file from HubSpot. Click here for more info |
Upload a new local asset to your HubSpot account. Changes uploaded through this command will be live immediately.
Argument | Description |
---|---|
src
Required
| Path to the local file, relative to your current working directory. |
dest
Required
| Path in HubSpot Design Tools, can be a net new path. |
Options | Description |
---|---|
--account
| Specify a Supports an alias of |
--mode
| Specify if uploaded files are published in HubSpot. See "modes" for more info. |
Subcommands | Description |
---|---|
filemanager
| Uploads the specified src directory to the File Manager, rather than to the developer file system in the Design Manager. Note: Uploaded files will be set to public, making them viewable by anyone with the URL. See our help documentation for more details on file visibility settings. |
Watch your local directory and automatically upload changes to your HubSpot account on file saves. Any changes made when saving will be live immediately.
Keep the following in mind when using watch
:
- Deleting watched files locally will not automatically delete them from HubSpot. To delete files, use
--remove
. - Renaming a folder locally will upload a new folder to HubSpot with the new name. The existing folder in HubSpot will not be deleted automatically. To delete the folder, use
--remove
.
In the past, the watch command would upload the current directory right away, then start watching for changes. This was changed in v2.0 to simply watch.
Argument | Description |
---|---|
src
Required
| Path to the local directory your files are in, relative to your current working directory |
dest
Required
| Path in HubSpot Design Tools, can be a net new path. |
Options | Description |
---|---|
--account
| Specify a Supports an alias of |
--mode
| Specify if uploaded files are published or saved as drafts in HubSpot. Learn more about using modes. |
--initial-upload
| Causes an initial upload to occur before file saves have occured. Supports an alias of |
--remove
| Will cause watch to delete files in your HubSpot account that are not found locally. |
--notify=<path/to/file>
| log to specified file when a watch task is triggered and after workers have gone idle. |
This command is currently in beta. Let us know if you have feedback through our developer slack or using an issue in the github for the CLI.
Moves files within the developer file system from one directory to another. Does not affect files stored locally.
Argument | Description |
---|---|
src
Required
| Path to the remote developer file system directory your files are in. |
dest
Required
| Path to move assets to within the developer file system. |
Options | Description |
---|---|
--account
| Specify a Supports an alias of |
Creates the folder/file structure of a new asset.
Argument | Description |
---|---|
type
Required
| Type of asset. Supported types: |
name
Required
| The name of the new asset |
dest
Optional
| The destination folder for the new asset, relative to your current working directory. If omitted, this will default to your current working directory. |
Deletes files, or folders and their files, from your HubSpot account. This does not delete the files and folders stored locally. This command has an alias of rm.
Argument | Description |
---|---|
path
Required
| Path in HubSpot Design Tools |
Options | Description |
---|---|
--account
| Specify a Supports an alias of |
The HubDB commands are currently in Developer Preview. They are available to use now but understand they are subject to change. Developer previews are subject to our developer beta terms.
Use these commands to create, delete, fetch, and clear all rows of a HubDB table. The HubSpot account must have access to HubDB to use these commands.
Create a new HubDB table in the HubSpot account.
Argument | Description |
---|---|
src
Required
| The local JSON file to use to generate the HubDB table. |
Options | Description |
---|---|
--account
| Specify a Supports an alias of |
Download a HubDB table's data to your computer.
Argument | Description |
---|---|
tableId
Required
| HubDB table id found in the HubDB dashboard. |
dest
| The local path destination to store the |
Options | Description |
---|---|
--account
| Specify a Supports an alias of |
Clear all of the rows in a HubDB table.
Argument | Description |
---|---|
tableId
Required
| HubDB table id found in the HubDB dashboard. |
Options | Description |
---|---|
--account
| Specify a Supports an alias of |
Deletes the specified HubDB table from the account.
Argument | Description |
---|---|
tableId
Required
| HubDB table id found in the HubDB dashboard. |
Options | Description |
---|---|
--account
| Specify a Supports an alias of |
When you fetch a HubDB the data is stored as tablename.hubdb.json
. When you create a new table you must specify a source JSON file. Below is an example of a table in JSON format.
Use these commands to create and debug serverless functions (CMS Hub Enterprise only).
Prints a list of all of the account's functions, their endpoints, methods, the names of the secrets they use and last updated date.
Argument | Description |
---|---|
--account
| The HubSpot account nickname from your hubspot.config. This parameter is required if you do not have a defaultAccount in your Supports an alias of |
--compact
| displays only endpoint names and methods. |
--json
| Output JSON into the command line with data on all of the functions. The JSON data includes, portal id, function id, route, raw asset path, method, secrets, created and last modified dates. |
Prints a log from your serverless function. Displays any console.logs
contained within your function after execution. Logs also include execution time. Logs are retained for 90 days.
Argument | Description |
---|---|
endpoint-name
Required
| The endpoint name as defined in your serverless.json file. It is not the path to your function file. |
Options | Description |
---|---|
--file
| Output the logs to function.log |
--follow
| Tail the logs to get a live update as you are executing your serverless functions. |
--latest
| Output only the most recent log |
--account
| The HubSpot account nickname from your hubspot.config. This parameter is required if you do not have a defaultPortal in your hubspot.config. Supports an alias of |
--compact
| hides log output/info. Returns success/error and execution time. |
--limit=<number>
| limit the amount of logs displayed in output |
If you receive this error: A server error occurred: WARNING: The logs for this function have exceeded the 4KB limit
, your log is too large. This can be caused by trying to console log a very large object, or by a lot of separate console logs. To resolve this, reduce how much you're trying to log, hit your endpoint, then run the command again.
Add a secret to your account which can be used within serverless functions. After running the command you will be prompted to enter the secret's value.
To expose the secret to your function, update your serverless.json
file with the secret's name, either to the specific endpoints you want to use it in or globally to make it available to all.
Argument | Description |
---|---|
secret-name
Required
| Name of secret. |
secret-value
Required
| The secret's value (auth detail, or otherwise). |
Update the value of a secret in your account which can be used within serverless functions. You will then be prompted to enter the secret's value.
Argument | Description |
---|---|
secret-name
Required
| Name of secret. |
secret-value
Required
| The secret's value (auth detail, or otherwise). |
Remove a secret from your account, making it no longer usable within serverless functions. After running this command, edit your serverless.json
file to remove the secret's name.
Argument | Description |
---|---|
secret-name
Required
| Name of secret you want to remove. |
List secrets within your account to know what you have stored already using the add secrets command.
There are so many parts of the HubSpot app that developers need to access frequently. To make it easier to get to these tools you can open them directly from the command line. Your defaultAccount
or --account
argument will be used to open the associated tool for that account.
Argument | Description |
---|---|
shortcut
Required
| Provide the full shortcut name or alias of the short cut you wish to open in your browser. |
Argument | Description |
---|---|
--list
Required
| Lists all of the shortcuts, their aliases and destinations. |
If you use the CLI frequently, it can be useful to be-able-to tab to auto-complete commands.
For Mac OS X
You can evaluate your themes and templates for their adherence to SEO best practices and accessibility recommendations. Scores are generated with Google's Lighthouse tools and only look at the desktop versions of pages. You will receive results in the following categories: Accessibility, Best Practices, Performance, PWA, and SEO.
Parameter | Description |
---|---|
-detail
| Show results for individual templates within a theme |
To learn about local template format annotations, refer to the templates documentation and view the templates in the CMS theme boilerplate.
Local modules are formatted in a series of files, each specifying various components of a module. To learn about developing modules locally, check out the Local Module Development Reference.
You can include a .hsignore file in your project to specify files that should not be tracked when using the CLI. This file functions similar to how .gitignore
files work. Files matching the patterns specified in the .hsignore file will not be uploaded to HubSpot when using the upload or watch commands.
By default there are some rules HubSpot automatically enforces. There is no way to override these defaults.
The following are always ignored:
hubspot.config.yml
/hubspot.config.yaml
node_modules
- dependencies.*
- hidden files/folders*.log
- NPM error log*.swp
- Swap file for Vim stateIcon\\r
- Mac OS custom Finder icon__MACOSX
- Mac resource fork~
Linux Backup fileThumbs.db
- Windows image file cacheehthumbs.db
- Windows folder config fileDesktop.ini
- Windows custom folder attribute information@eaDir
- Windows Synology diskstation "hidden" folder where the server stores thumbnails.
# ignore all files within a specific directory
/ignore/ignored
# ignore a specific file
/ignore/ignore.md
# ignore all .txt files
*.txt
# ignore all log files - useful if you commonly output serverless function logs as files.
*.log
The --mode option allows you to determine if local changes are published when uploaded to HubSpot. This option can be used in each command or set as a default in your hubspot.config.yml file.
The two options for --mode are --mode=draft and --mode=publish.
The following is the order of precedence for setting --mode:
- Using --mode in a command will override all other settings.
- Setting a defaultMode for each account in your hubspot.config.yml file, removes the need to use --mode in each command. It will override the top-level setting.
- Setting a defaultMode at the top-level in your hubspot.config.yml file, sets a default--mode for all accounts. It will override the default behavior.
- The default behavior for --mode is publish
The hubspot.config.yml file contains the credentials for your HubSpot accounts. See the Getting Started Guide for getting set up, or run the auth command to update an existing config file.
If you ran hs init
while using version v1.0.10 (released March 10, 2020) through v1.0.11 of the CLI your config file is placed at /Users/<username>/hubspot.config.yml
.
We have changed back to placing your config file in the folder you ran the command from, to make it obvious where the file is. You do not have to move your config file it will still work fine. If you prefer to keep your file with your project files, it is safe to move your file from this directory to your project folder. Do not commit this file into version control, it contains your auth credentials.
If you ran the command using any other version of the CMS-CLI your config file is placed in the folder you ran the command from.
Name | Description |
---|---|
defaultPortal
optional
| Replaces the need to run commands using |
defaultMode
optional
| Which mode should be used for an account, draft or publish. |
allowUsageTracking
optional
| Specifies if HubSpot has permission to track usage of the local development tools. Defaults to |
Name | Description |
---|---|
portalId
required
| The account ID of the account you are setting up authentication for. |
authType
required
| Which form of authentication a given entry is using. |
name
optional
| A means to specify a name of an account, which can be used to denote which account a command should interact with. ex. |
defaultMode
optional
| Which mode should be used for an account, draft or publish. |
The HubSpot CLI supports the use of environment variables, this can be especially useful when creating automations like a GitHub Action.
Run any command using the --use-env
flag to use the environment variables instead of the hubspot.config.yml
.
Name | Description |
---|---|
HUBSPOT_PORTAL_ID
Required
| The HubSpot account ID. |
HUBSPOT_PERSONAL_ACCESS_KEY
Recommended
| The personal access key of a user on the HubSpot account. All updates made will be associated to this user. |
HUBSPOT_API_KEY
| The HubSpot API key associated to the HubSpot account. |
HUBSPOT_CLIENT_ID
| The OAuth client ID. |
HUBSPOT_CLIENT_SECRET
| The OAuth secret. |
Please note: starting November 30, 2022, HubSpot API keys will no longer be able to be used as an authentication method to access HubSpot APIs. In addition, starting July 15, 2022, accounts without a HubSpot API key already generated will no longer be able to create one.
Instead, you'll need to use a private app access token or OAuth to authenticate API calls. Learn more about this change and how to migrate an API key integration to use a private app instead.
The CLI provides a suite of automated tests you can perform on your assets to get them in-line with the marketplace requirements prior to submitting. Passing all automated tests does not mean you will for sure pass the review process, further review is conducted to ensure quality beyond what can be easily automated.
The theme validation command allows you to quickly run automated tests on your theme to identify problems that need to be fixed prior to submission to the asset marketplace. These will be returned in your CLI as a list of [error] and [success] messages separated into groups that represent types of assets within a theme.
Argument | Description |
---|---|
src
Required
| Path to the local theme folder, relative to your current working directory. |
Thank you for your feedback, it means a lot to us.