# CRUD operations

> Source: https://docs.strapi.io/cms/api/entity-service/crud

The Entity Service API performs CRUD operations on content through `findOne()`, `findMany()`, `create()`, `update()`, and `delete()` methods, supporting filtering, pagination, relations, and localization.

:::caution
The Entity Service API is deprecated in Strapi v5. Please consider using the [Document Service API](/cms/api/document-service) instead.
:::

The [Entity Service API](/cms/api/entity-service) is built on top of the the [Query Engine API](/cms/api/query-engine) and uses it to perform CRUD operations on entities.

The `uid` parameter used in function calls for this API is a `string` built with the following format: `[category]::[content-type]` where `category` is one of: `admin`, `plugin` or `api`.

Examples:
- A correct `uid` to get users of the Strapi admin panel is `admin::user`.
- A possible `uid` for the Upload plugin could be `plugin::upload.file`.
- As the `uid`s for user-defined custom content-types follow the `api::[content-type]` syntax, if a content-type `article` exists, it is referenced by `api::article.article`.

:::tip
Run the [`strapi content-types:list`](/cms/cli#strapi-content-typeslist) command in a terminal to display all possible content-types' `uid`s for a specific Strapi instance.
:::

## findOne()

Finds the first entry matching the parameters.

Syntax: `findOne(uid: string, id: ID, parameters: Params)` ⇒ `Entry`

### Parameters

| Parameter  | Description | Type |
| ---------- | --------------- | --------------- |
| `fields`   | Attributes to return | `String[]`  |
| `populate` | Relations, components and dynamic zones to [populate](/cms/api/entity-service/populate) | [`PopulateParameter`](/cms/api/entity-service/populate) |
| `locale` | Locale code (for example `fr-FR`) when the Internationalization plugin is enabled. Targets the localized variant instead of the default locale. | `string` |

### Example

```js
const entry = await strapi.entityService.findOne('api::article.article', 1, {
  fields: ['title', 'description'],
  populate: { category: true },
});
```

## findMany()

Finds entries matching the parameters.

Syntax: `findMany(uid: string, parameters: Params)` ⇒ `Entry[]`

### Parameters

| Parameter   | Description | Type   |
| ----------- | ------ | -------------- |
| `fields`  | Attributes to return   | `String[]`  |
| `filters` | [Filters](/cms/api/entity-service/filter) to use   | [`FiltersParameters`](/cms/api/entity-service/filter)             |
| `start`   | Number of entries to skip (see [pagination](/cms/api/entity-service/order-pagination#pagination))   | `Number`  |
| `limit`   | Number of entries to return (see [pagination](/cms/api/entity-service/order-pagination#pagination)) | `Number`  |
| `sort`   | [Order](/cms/api/entity-service/order-pagination) definition  | [`OrderByParameter`](/cms/api/entity-service/order-pagination) |
| `populate`  | Relations, components and dynamic zones to [populate](/cms/api/entity-service/populate)  | [`PopulateParameter`](/cms/api/entity-service/populate)         |
| `publicationState` | Publication state, can be:<ul><li>`live` to return only published entries</li><li>`preview` to return both draft entries & published entries (default)</li></ul>   | `PublicationStateParameter`  |
| `locale` | Locale code when the Internationalization plugin is enabled. Restricts results to that locale (omit for the default locale). | `string` |

### Example

```js
const entries = await strapi.entityService.findMany('api::article.article', {
  fields: ['title', 'description'],
  filters: { title: 'Hello World' },
  sort: { createdAt: 'DESC' },
  populate: { category: true },
});
```

<br/>

:::tip
To retrieve only draft entries, combine the `preview` publication state and the `publishedAt` fields:

```js
const entries = await strapi.entityService.findMany('api::article.article', {
  publicationState: 'preview',
  filters: {
    publishedAt: {
      $null: true,
    },
  },
});

:::

## create()

Creates one entry and returns it

Syntax: `create(uid: string, parameters: Params)` ⇒ `Entry`

### Parameters

| Parameter  | Description | Type |
| ---------- | ----------- | ---------- |
| `fields`   | Attributes to return | `String[]`  |
| `populate` | Relations, components and dynamic zones to [populate](/cms/api/entity-service/populate) | [`PopulateParameter`](/cms/api/entity-service/populate) |
| `locale` | Locale code when the Internationalization plugin is enabled. Creates the entry for that locale. | `string` |
| `data`     | Input data  | `Object` |

:::tip
In the `data` object, relations can be managed with the `connect`, `disconnect`, and `set` parameters using the syntax described for the REST API (see [managing relations](/cms/api/rest/relations)).
:::

### Example

```js
const entry = await strapi.entityService.create('api::article.article', {
  data: {
    title: 'My Article',
  },
});
```

## update()

Updates one entry and returns it.

:::note
`update()` only performs a partial update, so existing fields that are not included won't be replaced.
:::

Syntax: `update(uid: string, id: ID, parameters: Params)` ⇒ `Entry`

:::tip
In the `data` object, relations can be managed with the `connect`, `disconnect`, and `set` parameters using the syntax described for the REST API (see [managing relations](/cms/api/rest/relations)).
:::

### Parameters

| Parameter  | Description | Type |
| ---------- | ------------- | ---------- |
| `fields`   | Attributes to return | `String[]`  |
| `populate` | Relations, components and dynamic zones to [populate](/cms/api/entity-service/populate) | [`PopulateParameter`](/cms/api/entity-service/populate) |
| `locale` | Locale code when the Internationalization plugin is enabled. Updates the matching localized variant. | `string` |
| `data`     | Input data  | `object`  |

### Example

```js
const entry = await strapi.entityService.update('api::article.article', 1, {
  data: {
    title: 'xxx',
  },
});
```

## delete()

Deletes one entry and returns it.

Syntax: `delete(uid: string, id: ID, parameters: Params)` ⇒ `Entry`

### Parameters

| Parameter  | Description | Type |
| ---------- | --------- | -------- |
| `fields`   | Attributes to return | `String[]`  |
| `populate` | Relations, components and dynamic zones to [populate](/cms/api/entity-service/populate) | [`PopulateParameter`](/cms/api/entity-service/populate) |
| `locale` | Locale code when the Internationalization plugin is enabled. Deletes the localized variant that matches this locale. | `string` |

### Example

```js
const entry = await strapi.entityService.delete('api::article.article', 1);
```
