# Sphere

**Manage commercetools API resources from the terminal.**

The `sphere` topic provides commands for supported [commercetools API](/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](/dev-tooling/cli/overview.md#authentication).

## Command pattern

```bash title="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](/dev-tooling/cli/sphere.md#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

```bash title="List products with filtering and sorting"
commercetools sphere products list 
  --limit 10 
  --where 'masterData(published=true)' 
  --sort 'lastModifiedAt desc'
```

```bash title="Get a product by key"
commercetools sphere products get --key my-product-key
```

```bash title="Create a category from a JSON file"
commercetools sphere categories create --body @category.json
```

```bash title="Update a product type"
commercetools sphere product-types update 
  --key my-product-type 
  --version 3 
  --actions '[{"action":"changeName","name":{"en":"Updated Name"}}]'
```

```bash title="Delete a discount code"
commercetools sphere discount-codes delete --id abc123 --version 1
```

```bash title="Pipe output to jq"
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:

```bash title="Custom Object commands"
# 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](/api/predicates/query.md). 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](/api/projects/products.md#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 |

## Related pages

- [Area overview page with navigation](/dev-tooling.md)
- [Previous page: Overview](/dev-tooling/cli/overview.md)
- [Next page: Commerce Integration Layer](/dev-tooling/cli/integration-layer.md)
- [Search documentation and API specs](/search.md)