Copy as Markdown[View as Markdown](/docs/cli/cli-queries.md)

***

# Queries CLI Commands

Manage queries in your EventCatalog from the command line.

## getQuery[​](#getquery "Direct link to getQuery")

Returns a query from EventCatalog by its ID

**Arguments:**

| Name    | Type   | Required | Description                     |
| ------- | ------ | -------- | ------------------------------- |
| id      | string | Yes      | The ID of the query to retrieve |
| version | string | No       | Specific version to retrieve    |

**Examples:**

```
# Get the latest query
npx @eventcatalog/cli getQuery "GetOrder"

# Get a specific version
npx @eventcatalog/cli getQuery "GetOrder" "1.0.0"
```

***

## getQueries[​](#getqueries "Direct link to getQueries")

Returns all queries from EventCatalog

**Arguments:**

| Name    | Type | Required | Description                           |
| ------- | ---- | -------- | ------------------------------------- |
| options | json | No       | Options: {latestOnly?, attachSchema?} |

**Examples:**

```
# Get all queries
npx @eventcatalog/cli getQueries
```

***

## writeQuery[​](#writequery "Direct link to writeQuery")

Writes a query to EventCatalog

**Arguments:**

| Name    | Type | Required | Description                                          |
| ------- | ---- | -------- | ---------------------------------------------------- |
| query   | json | Yes      | Query object with id, name, version, and markdown    |
| options | json | No       | Options: {path?, override?, versionExistingContent?} |

***

## writeQueryToService[​](#writequerytoservice "Direct link to writeQueryToService")

Writes a query to a specific service

**Arguments:**

| Name    | Type | Required | Description                          |
| ------- | ---- | -------- | ------------------------------------ |
| query   | json | Yes      | Query object                         |
| service | json | Yes      | Service reference: {id, version?}    |
| options | json | No       | Options: {path?, format?, override?} |

***

## rmQuery[​](#rmquery "Direct link to rmQuery")

Removes a query by its path

**Arguments:**

| Name | Type   | Required | Description       |
| ---- | ------ | -------- | ----------------- |
| path | string | Yes      | Path to the query |

**Examples:**

```
# Remove a query
npx @eventcatalog/cli rmQuery "/GetOrder"
```

***

## rmQueryById[​](#rmquerybyid "Direct link to rmQueryById")

Removes a query by its ID

**Arguments:**

| Name    | Type   | Required | Description                   |
| ------- | ------ | -------- | ----------------------------- |
| id      | string | Yes      | The ID of the query to remove |
| version | string | No       | Specific version to remove    |

**Examples:**

```
# Remove a query
npx @eventcatalog/cli rmQueryById "GetOrder"
```

***

## versionQuery[​](#versionquery "Direct link to versionQuery")

Moves the current query to a versioned directory

**Arguments:**

| Name | Type   | Required | Description                    |
| ---- | ------ | -------- | ------------------------------ |
| id   | string | Yes      | The ID of the query to version |

**Examples:**

```
# Version a query
npx @eventcatalog/cli versionQuery "GetOrder"
```

***

## addFileToQuery[​](#addfiletoquery "Direct link to addFileToQuery")

Adds a file to a query

**Arguments:**

| Name    | Type   | Required | Description                      |
| ------- | ------ | -------- | -------------------------------- |
| id      | string | Yes      | The ID of the query              |
| file    | json   | Yes      | File object: {content, fileName} |
| version | string | No       | Specific version                 |

***

## addSchemaToQuery[​](#addschematoquery "Direct link to addSchemaToQuery")

Adds a schema to a query

**Arguments:**

| Name    | Type   | Required | Description                       |
| ------- | ------ | -------- | --------------------------------- |
| id      | string | Yes      | The ID of the query               |
| schema  | json   | Yes      | Schema object: {schema, fileName} |
| version | string | No       | Specific version                  |

***

## queryHasVersion[​](#queryhasversion "Direct link to queryHasVersion")

Checks if a specific version of a query exists

**Arguments:**

| Name    | Type   | Required | Description         |
| ------- | ------ | -------- | ------------------- |
| id      | string | Yes      | The ID of the query |
| version | string | Yes      | Version to check    |

**Examples:**

```
# Check if version exists
npx @eventcatalog/cli queryHasVersion "GetOrder" "1.0.0"
```

***
