Manage commercetools API resources from the terminal.
The
sphere topic provides commands for supported commercetools API resources. The available operations depend on the resource. Most resources follow the five-command pattern below, but Product Projections are read-only, and API Clients do not support updates.Commands that call the API need an authenticated session. For how to log in, see Authentication.
Command pattern
commercetools sphere <resource> list [--limit <n>] [--offset <n>] [--where <predicate>] [--sort <expr>]
commercetools sphere <resource> get --id <id> [| --key <key>]
commercetools sphere <resource> create --body <json | @filepath>
commercetools sphere <resource> update --id <id> [| --key <key>] --version <n> --actions <json | @filepath>
commercetools sphere <resource> delete --id <id> [| --key <key>] --version <n>
All resources support
--id for get, update, and delete. Resources that also support --key allow you to use a human-readable identifier instead.Resources
The following resources are available under the
sphere topic:| Resource | Also supports --key |
|---|---|
api-clients | No |
approval-flows | No |
approval-rules | Yes |
associate-roles | Yes |
attribute-groups | Yes |
business-units | Yes |
cart-discounts | Yes |
carts | No |
categories | Yes |
channels | Yes |
custom-objects | See Custom Objects |
customer-groups | Yes |
customers | Yes |
discount-codes | Yes |
discount-groups | Yes |
extensions | Yes |
inventory | No |
orders | Yes |
payment-methods | Yes |
payments | Yes |
product-discounts | Yes |
product-projections | Yes |
product-selections | Yes |
product-tailoring | Yes |
product-types | Yes |
products | Yes |
quote-requests | Yes |
quotes | Yes |
reviews | No |
shipping-methods | Yes |
shopping-lists | Yes |
staged-quotes | Yes |
states | Yes |
stores | Yes |
subscriptions | Yes |
tax-categories | Yes |
types | Yes |
zones | Yes |
Examples
commercetools sphere products list \
--limit 10 \
--where 'masterData(published=true)' \
--sort 'lastModifiedAt desc'
commercetools sphere products get --key my-product-key
commercetools sphere categories create --body @category.json
commercetools sphere product-types update \
--key my-product-type \
--version 3 \
--actions '[{"action":"changeName","name":{"en":"Updated Name"}}]'
commercetools sphere discount-codes delete --id abc123 --version 1
commercetools sphere products list --limit 100 | jq '.results[].key'
Custom Objects
Custom Objects have a unique URL structure (
/custom-objects/{container}/{key}) and use slightly different flags:# List all custom objects (optionally filter by container)
commercetools sphere custom-objects list [--container <name>]
# Get a specific custom object
commercetools sphere custom-objects get --container <name> --key <key>
# Create or replace a custom object
commercetools sphere custom-objects create --body '{"container":"my-container","key":"my-key","value":{"foo":"bar"}}'
# Delete a custom object
commercetools sphere custom-objects delete --container <name> --key <key>
Flag reference
list
| Flag | Description | Default |
|---|---|---|
--limit | Maximum number of results | 20 |
--offset | Number of results to skip | 0 |
--where | Query predicate. Can be repeated. | |
--sort | Sort expression. Can be repeated. |
get
| Flag | Description |
|---|---|
--id | Resource ID |
--key | Resource key (only for resources that support keys) |
create
| Flag | Description |
|---|---|
--body | JSON string or path to a JSON file prefixed with @ |
update
| Flag | Description |
|---|---|
--id | Resource ID |
--key | Resource key |
--version | Current version of the resource (required for optimistic concurrency) |
--actions | JSON array of update actions or path to a JSON file prefixed with @ |
delete
| Flag | Description |
|---|---|
--id | Resource ID |
--key | Resource key |
--version | Current version of the resource |