This project is designed as a tool for power users to interact with the Elastic Path Composable Commerce API via the command line and the project is designed to fill three distinct niches:
This tool is not meant for new users unfamiliar with the API, new users are highly encouraged to use the Elastic Path Composable Commerce Postman Collection instead of this tool.
Additionally, this tool is not necessarily meant to be a new command line equivalent of Commerce Manager, it should just feel at all times like you are interacting with a JSON based REST API.
epcc
binary to your path.It is highly recommended that new users check out the Tutorial.
The following is a summary of the main commands, in general you can type epcc help
to get an updated list and see all commands as well as flags.
Command | Description |
---|---|
epcc get <RESOURCE> [ID] ... [QUERY_PARAM_KEY] [VAL] ... |
Retrieves either a list of objects, or an particular object from the API. |
epcc create <RESOURCE> [ID]... [KEY] [VAL] [KEY] [VAL]... |
Create an object. |
epcc update <RESOURCE> [ID]...[KEY] [VAL] [KEY] [VAL]... |
Update an object. |
epcc delete <RESOURCE> [ID]... |
Delete an object. |
Command | Description |
---|---|
epcc login client_credentials |
Login to the API using a Client Credential Token |
epcc login customer |
Login to the API using a Customer Token |
epcc login account-management |
Login to the API using an Account Management Authentication Token |
epcc login implicit |
Login to the API using an Implicit Token |
epcc login status |
Determine the current state of the login |
Command | Description |
---|---|
epcc docs <RESOURCE> |
Open the API docs for a resource in your browser |
epcc docs <RESOURCE> [create/read/update/delete] |
Open the API docs for a resource with a specification action in your browser |
epcc aliases list |
List all known resource aliases |
epcc resource-list |
List all supported resources |
epcc test-json [KEY] [VAL] [KEY] [VAL] ... |
Render a JSON document based on the supplied key and value pairs |
Command | Description |
---|---|
epcc reset-store <STORE_ID> |
Reset the store to an initial state (on a best effort basis) |
epcc runbooks show <RUNBOOK> <ACTION> |
Show a specific runbook (script) |
epcc runbooks validate |
Validates all runbooks (built in and user supplied, outputting any errors) |
epcc runbooks run <RUNBOOK> <ACTION> |
Run a specific runbook (script) |
--execution-timeout
will control how long the epcc
process can run before timing out.--rate-limit
will control the number of requests per second to EPCC.--max-concurrency
will control the maximum number of concurrent commands that can run simultaneously.
--max-concurrency
would limit you to 3. A higher value will slow down initial start time.Headers can be set in one of three ways, depending on what is most convenient
-H
argument.
EPCC_CLI_HTTP_HEADER_0
environment variable.
epcc header set
epcc headers status
--group
and then clear all headers with epcc headers clear <GROUP>
Run the epcc configure
and it will prompt you for the required settings, when you execute any EPCC CLI command you can pass in the --profile
argument, or set the EPCC_PROFILE
environment variable to use that profile.
The following environment variables can be set up to control which environment and store to use with the EPCC CLI.
Environment Variable | Description |
---|---|
EPCC_API_BASE_URL | This is the API base URL which can be retrieved via CM. |
EPCC_BETA_API_FEATURES | This variable allows you to set Beta Headers for all API calls. |
EPCC_CLI_HTTPHEADERN | Setting any environment variable like this (where N is a number) will cause it's value to be parsed and added to all HTTP headers (e.g., EPCC_CLI_HTTP_HEADER_0=Cache-Control: no-cache will add Cache-Control: no-cache as a header). FYI, the surprising syntax is due to different encoding rules. You can also specify headers using -H or epcc headers . |
EPCC_CLI_SUPPRESS_NO_AUTH_MESSAGES | This will supress warning messages about not being authenticated or logged out |
EPCC_CLI_URL_MATCHREGEXPN | Setting this value causes the path section of a URL to be matched and replaced with a corresponding value from the EPCC_CLI_URL_MATCH_SUBSTITION_**N** header, if not set the empty string is used. |
EPCC_CLI_URL_MATCHSUBSTITIONN | The replacement string to use when a match is found. Capture groups and back references are supported (see ReplaceAllString). |
EPCC_CLIENT_ID | This is the Client ID which can be retrieved via CM. |
EPCC_CLIENT_SECRET | This is the Client Secret which can be retrieved via CM. |
EPCC_PROFILE | A profile name that allows for an independent session and isolation (e.g., distinct histories). |
EPCC_RUNBOOK_DIRECTORY | A directory that will be scanned for runbook, a runbook ends with .epcc.yml . |
It is recommended to set EPCC_API_BASE_URL, EPCC_CLIENT_ID, and EPCC_CLIENT_SECRET to be able to interact with most things in the CLI.
For convenience this cli has been set up with auto-completion. To make the most of the EPCC CLI start by running the following commands to set up completion for your shell:
If shell completion is not already enabled in your environment, you will need to enable it. Run the following command once:
echo "autoload -U compinit; compinit" >> ~/.zshrc
To load completions for each session, execute once:
epcc completion zsh > “${fpath[1]}/_epcc
You will need to start a new shell for this setup to take effect
You will need to have the bash-completion ( e.g., Ubuntu, Arch, Gentoo) package installed, and restart your bash session.
To load completions for each session, execute once:
epcc completion bash > /etc/bash_completion.d/epcc
epcc completion bash > /usr/local/etc/bash_completion.d/epcc
For PowerShell run:
epcc completion powershell | Out-String | Invoke-Expression
To load completions for every new session, run:
epcc completion powershell > epcc.ps1
and source this file from your PowerShell profile.
For fish run:
epcc completion fish | source
To load completions for each session, execute once:
epcc completion fish > ~/.config/fish/completions/epcc.fish
The --output-jq
option can post process the output of epcc create
epcc get
and epcc update
, for instance the following can be used to create richer
output.
$epcc create customer --auto-fill
INFO[0000] (0001) POST https://api.moltin.com/v2/customers ==> HTTP/2.0 201 Created
{
"data": {
"type": "customer",
"id": "49d8e601-d110-42b7-99d2-60db73a6fb62",
"authentication_mechanism": "password",
"email": "thorabartell@gutmann.org",
"name": "Michele Schuppe",
"password": false
}
}
$epcc create customer --auto-fill
INFO[0001] (0001) POST https://api.moltin.com/v2/customers ==> HTTP/2.0 201 Created
{
"data": {
"type": "customer",
"id": "bf642721-44e5-4919-9fa5-b9c7da1ded1f",
"authentication_mechanism": "password",
"email": "kavondonnelly@yost.info",
"name": "Matt Robel",
"password": false
}
}
$epcc get customers --output-jq '.data[] | "\(.name) has id \(.id)"'
INFO[0000] (0001) GET https://api.moltin.com/v2/customers ==> HTTP/2.0 200 OK
[
"Michele Schuppe has id 49d8e601-d110-42b7-99d2-60db73a6fb62",
"Matt Robel has id bf642721-44e5-4919-9fa5-b9c7da1ded1f"
]
The JQ Manual has some additional guidance on syntax, although this is based on GoJQ which has a number of differences.
The --retry-while-jq
argument can be used to wait for certain conditions to happen (e.g., a catalog publication, or an eventual consistency condition).
For example:
epcc get pcm-catalog-release --retry-while-jq '.data.meta.release_status != "PUBLISHED"' name=Ranges_Catalog last_release
The JQ Manual has some additional guidance on syntax, although this is based on GoJQ which has a number of differences.
epcc runbooks run misc get-store-info
For development the following command using Reflex can speed up your development time, by recreating the command line tool.
git fetch --all --tags && reflex -v -s -r '(\.go$)|(resources.yaml|go.mod)|(runbooks/.+\.ya?ml)$' -- sh -c "go build -ldflags=\"-X github.com/elasticpath/epcc-cli/external/version.Version=$(git describe --tags --abbrev=0)+1 -X github.com/elasticpath/epcc-cli/external/version.Commit=$(git rev-parse --short HEAD)-dirty\" -o ./epcc"
The following git pre-commit hook will run go fmt before committing anything
#!/bin/bash
echo "Running go fmt"
go fmt "./..."
echo "Adding changed files back to git"
git diff --cached --name-only --diff-filter=ACM | grep -E "\.(go)$" | xargs git add