> ## Documentation Index
> Fetch the complete documentation index at: https://docs.occtoo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# occtoo destinations

> Manage destinations: the APIs that publish card entries, their versions and endpoints

A destination is an API that publishes card entries. A destination has versions, a version has endpoints, and an endpoint returns properties of one card.

Wherever a command asks for a version, you can pass `latest` for the highest one.

## From nothing to a published API

```bash theme={null}
occtoo destinations create
occtoo destinations versions create webshop
occtoo destinations endpoints create webshop latest
occtoo destinations publish webshop
```

1. Create the destination.
2. Create its first version, with access and languages.
3. Add an endpoint. In a terminal, you pick a card and its properties.
4. Publish the version and wait until it is live.

## Destinations

```bash theme={null}
occtoo destinations list
occtoo destinations show webshop
occtoo destinations create --file destination.json
occtoo destinations edit webshop
occtoo destinations delete webshop --yes
```

| Command | What it does |
| - | - |
| `list` | Lists destinations. `--name` filters by name, `--limit` defaults to `100` |
| `show <ID>` | Shows a destination and its versions |
| `create` | Creates a destination from prompts or JSON. A new destination has no versions |
| `edit <ID>` | Changes the name, description or tags. In JSON, a field you leave out stays as it is |
| `delete <ID>` | Deletes a destination for good. Refused while it has a version, so delete its versions first |

JSON for `create`. `description` and `tags` are optional:

```json theme={null}
{ "id": "webshop", "name": "Webshop", "description": "...", "tags": ["commerce"] }
```

The id is 3 to 50 letters and digits. It becomes part of the address of the published API and can't change.

## Publish

```bash theme={null}
occtoo destinations publish webshop
occtoo destinations publish webshop 2
```

Publishes a version, or the pending content of a published version, and waits until it is live. The version defaults to `latest`. Progress goes to stderr. Ctrl-C stops the waiting, not the publish. `occtoo destinations versions show` tells you how far it is.

## Versions

```bash theme={null}
occtoo destinations versions list webshop
occtoo destinations versions show webshop
occtoo destinations versions create webshop
occtoo destinations versions edit webshop latest
occtoo destinations versions delete webshop 1 --yes
```

| Command | What it does |
| - | - |
| `versions list <DESTINATION>` | Lists the versions. `--limit` defaults to `100` |
| `versions show <DESTINATION> [VERSION]` | Shows a version with its endpoints and the steps of its latest publish |
| `versions create <DESTINATION>` | Creates a version. See below |
| `versions edit <DESTINATION> <VERSION>` | Changes the languages, allowed origins or description |
| `versions delete <DESTINATION> <VERSION>` | Deletes a version and what it published. It has the state `DeleteStarted` until it is gone |

The first version takes its settings from prompts or JSON. `allowedOrigins` and `description` are optional:

```json theme={null}
{
  "authentication": "Protected",
  "defaultLanguage": "en",
  "languages": [
    { "language": "en", "sourceLanguage": "en" },
    { "language": "sv", "sourceLanguage": "sv" }
  ],
  "allowedOrigins": ["https://shop.example.com"]
}
```

* `authentication` is `Protected` (callers send an access token) or `AllowAnonymous`. It can't change later.
* `language` is the code callers send. `sourceLanguage` is the language of the card data served for it.

A later version is a copy of the latest one, with its endpoints, and takes no input. The latest version has to be published first.

JSON for `versions edit`. Every field is optional:

```json theme={null}
{
  "languages": [{ "language": "en", "sourceLanguage": "en" }],
  "defaultLanguage": "en",
  "allowedOrigins": ["*"],
  "description": "..."
}
```

## Endpoints

```bash theme={null}
occtoo destinations endpoints list webshop
occtoo destinations endpoints show webshop latest products
occtoo destinations endpoints create webshop latest --file endpoint.json
occtoo destinations endpoints edit webshop latest products
occtoo destinations endpoints discard webshop latest products --yes
occtoo destinations endpoints delete webshop latest products --yes
```

| Command | What it does |
| - | - |
| `endpoints list <DESTINATION> [VERSION]` | Lists the endpoints of a version. `--limit` defaults to `100` |
| `endpoints show <DESTINATION> <VERSION> <ENDPOINT>` | Shows what an endpoint returns and the content waiting for the next publish |
| `endpoints create <DESTINATION> <VERSION>` | Adds an endpoint. In a terminal, you build it from a card |
| `endpoints edit <DESTINATION> <VERSION> <ENDPOINT>` | Changes what an endpoint returns. In a terminal, you tick the properties |
| `endpoints discard <DESTINATION> <VERSION> <ENDPOINT>` | Throws away the content waiting for the next publish |
| `endpoints delete <DESTINATION> <VERSION> <ENDPOINT>` | Deletes an endpoint. Refused for the last endpoint of a published version |

JSON for `endpoints create`. `description`, `alias`, `facet`, `segments` and `relations` are optional:

```json theme={null}
{
  "id": "products",
  "name": "Products",
  "content": {
    "cardId": "product",
    "properties": [{ "id": "title" }, { "id": "brand", "alias": "brandName", "facet": { "size": 20 } }],
    "segments": { "include": ["summer"], "exclude": ["outlet"] },
    "relations": [
      {
        "id": "productVariants",
        "alias": "variants",
        "cardinality": "Plural",
        "content": { "cardId": "variant", "properties": [{ "id": "sku" }] }
      }
    ]
  }
}
```

JSON for `endpoints edit`. `content` replaces everything the endpoint returns, so send all of it:

```json theme={null}
{ "content": { "cardId": "product", "properties": [{ "id": "title" }, { "id": "price" }] } }
```

To start from what is there:

```bash theme={null}
occtoo destinations endpoints show webshop latest products --output json | jq '{content}'
```

### Endpoints on a published version

Before its version is published, an endpoint changes at once. On a published version, new content waits as pending until the next `occtoo destinations publish`. Pending content can add properties, relations and facets, but can't remove them or change an alias. The name and description are fixed.

## Search what an endpoint publishes

```bash theme={null}
occtoo destinations entries search webshop latest products --sort name --limit 5
occtoo destinations entries search webshop 1 products --output json | jq '.items[].content'
```

Finds the entries that one endpoint publishes, each as the endpoint shows it.

| Flag | Description |
| - | - |
| `--where <JSON>` | Only entries that match this [search predicate](https://docs.occtoo.com/cli/commands/cards.md#search-predicates), over the properties of the endpoint |
| `--language <LANGUAGE>` | The language to search in, for localized values |
| `--sort <PROPERTY[:asc\|desc]>` | Order by this property. Add `:desc` for largest first. Repeat for several |
| `--count` | Count every matching entry |
| `--limit <LIMIT>` | Maximum number of entries to return. Default `50` |
| `--file <FILE>` | Read the whole search request from a JSON file, for paging by cursor |

```json theme={null}
{
  "where": {},
  "language": "en",
  "sort": [{ "property": "name", "direction": "Ascending" }],
  "limit": 500,
  "after": "...",
  "includeTotalCount": true
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.