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

***

# Function: addEntityToService()

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

Defined in: services.ts:535

Add an entity to a service by its id.

## 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';

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

// adds a new entity (User) to the InventoryService
await addEntityToService('InventoryService', { id: 'User', version: '1.0.0' });

// adds a new entity (Product) to a specific version of the InventoryService
await addEntityToService('InventoryService', { id: 'Product', version: '1.0.0' }, '2.0.0');
```
