Sphere

Ask about this Page
Copy for AI
View as Markdown

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

Command patternbash
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:
ResourceAlso supports --key
api-clientsNo
approval-flowsNo
approval-rulesYes
associate-rolesYes
attribute-groupsYes
business-unitsYes
cart-discountsYes
cartsNo
categoriesYes
channelsYes
custom-objectsSee Custom Objects
customer-groupsYes
customersYes
discount-codesYes
discount-groupsYes
extensionsYes
inventoryNo
ordersYes
payment-methodsYes
paymentsYes
product-discountsYes
product-projectionsYes
product-selectionsYes
product-tailoringYes
product-typesYes
productsYes
quote-requestsYes
quotesYes
reviewsNo
shipping-methodsYes
shopping-listsYes
staged-quotesYes
statesYes
storesYes
subscriptionsYes
tax-categoriesYes
typesYes
zonesYes

Examples

List products with filtering and sortingbash
commercetools sphere products list \
  --limit 10 \
  --where 'masterData(published=true)' \
  --sort 'lastModifiedAt desc'
Get a product by keybash
commercetools sphere products get --key my-product-key
Create a category from a JSON filebash
commercetools sphere categories create --body @category.json
Update a product typebash
commercetools sphere product-types update \
  --key my-product-type \
  --version 3 \
  --actions '[{"action":"changeName","name":{"en":"Updated Name"}}]'
Delete a discount codebash
commercetools sphere discount-codes delete --id abc123 --version 1
Pipe output to jqbash
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:
Custom Object commandsbash
# 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

FlagDescriptionDefault
--limitMaximum number of results20
--offsetNumber of results to skip0
--whereQuery predicate. Can be repeated.
--sortSort expression. Can be repeated.

get

FlagDescription
--idResource ID
--keyResource key (only for resources that support keys)

create

FlagDescription
--bodyJSON string or path to a JSON file prefixed with @

update

FlagDescription
--idResource ID
--keyResource key
--versionCurrent version of the resource (required for optimistic concurrency)
--actionsJSON array of update actions or path to a JSON file prefixed with @

delete

FlagDescription
--idResource ID
--keyResource key
--versionCurrent version of the resource