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

***

# Function: addEntityToDomain()

> **addEntityToDomain**(`directory`): (`id`, `entity`, `version`?) => `Promise`<`void`>

Defined in: domains.ts:446

Add an entity to a domain by its id. Optionally specify a version to add the entity to a specific version of the domain.

## 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`                                 |
| `entity`          | { `id`: `string`; `version`: `string`; } |
| `entity.id`       | `string`                                 |
| `entity.version`? | `string`                                 |
| `version`?        | `string`                                 |

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

`Promise`<`void`>

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

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

// Adds an entity to the domain
const { addEntityToDomain } = utils('/path/to/eventcatalog');

// Adds an entity (User) to the domain (Orders)
await addEntityToDomain('Orders', { id: 'User', version: '1.0.0' });
// Adds an entity (Product) to the domain (Orders) with a specific version
await addEntityToDomain('Orders', { id: 'Product', version: '2.0.0' }, '1.0.0');
```
