Copy as Markdown[View as Markdown](/docs/sdk/functions/getSchemaForMessage.md)

***

# Function: getSchemaForMessage()

> **getSchemaForMessage**(`directory`): (`id`, `version`?) => `Promise`<{ `fileName`: `string`; `schema`: `string`; }>

Defined in: messages.ts:194

Returns the schema for a given message (event, command or query) by its id and version.

If no version is given, the latest version is used.

## Parameters[​](#parameters "Direct link to Parameters")

| Parameter   | Type     |
| ----------- | -------- |
| `directory` | `string` |

## Returns[​](#returns "Direct link to Returns")

`Function`

### Parameters[​](#parameters-1 "Direct link to Parameters")

| Parameter  | Type     |
| ---------- | -------- |
| `id`       | `string` |
| `version`? | `string` |

### Returns[​](#returns-1 "Direct link to Returns")

`Promise`<{ `fileName`: `string`; `schema`: `string`; }>

## Example[​](#example "Direct link to Example")

```
import utils from '@eventcatalog/utils';

const { getSchemaForMessage } = utils('/path/to/eventcatalog');

// Get the schema for the latest version of the message
const schema = await getSchemaForMessage('InventoryAdjusted');

// Get the schema for a specific version
const schema = await getSchemaForMessage('InventoryAdjusted', '0.0.1');
```
