# Entity Service API: CRUD operations

The Entity Service API is built on top of the the Query Engine API and uses it to perform CRUD operations on entities.

# 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 PopulateParameter

# Example

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 to use FiltersParameters
start Number of entries to skip (see pagination) Number
limit Number of entries to return (see pagination) Number
sort Order definition OrderByParameter
populate Relations, components and dynamic zones to populate PopulateParameter
publicationState Publication state, can be:
  • live to return only published entries (default)
  • preview to return both draft entries & published entries
PublicationStateParameter

# Example

const entries = await strapi.entityService.findMany('api::article.article', {
  fields: ['title', 'description'],
  filters { title: 'Hello World' },
  sort: { createdAt: 'DESC' },
  populate: { category: 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 PopulateParameter
data Input data Object

# Example

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

# Parameters

Parameter Description Type
fields Attributes to return String[]
populate Relations, components and dynamic zones to populate PopulateParameter
data Input data object

# Example

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 PopulateParameter

# Example

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