# Entity Service API: Components and dynamic zones
The Entity Service is the layer that handles components and dynamic zones logic. With the Entity Service API, components and dynamic zones can be created and updated while creating or updating entries.
# Creation
A component can be created while creating an entry with the Entity Service API:
strapi.entityService.create('api::article.article', {
data: {
myComponent: {
foo: 'bar',
},
},
});
2
3
4
5
6
7
A dynamic zone (i.e. a list of components) can be created while creating an entry with the Entity Service API:
strapi.entityService.create('api::article.article', {
data: {
myDynamicZone: [
{
__component: 'compo.type',
foo: 'bar',
},
{
__component: 'compo.type2',
foo: 'bar',
},
],
},
});
2
3
4
5
6
7
8
9
10
11
12
13
14
# Update
A component can be updated while updating an entry with the Entity Service API. If a component id
is specified, the component is updated, otherwise the old one is deleted and a new one is created:
strapi.entityService.update('api::article.article', 1, {
data: {
myComponent: {
id: 1, // will update component with id: 1 (if not specified, would have deleted it and created a new one)
foo: 'bar',
},
},
});
2
3
4
5
6
7
8
A dynamic zone (i.e. a list of components) can be updated while updating an entry with the Entity Service API. If a component id
is specified, the component is updated, otherwise the old one is deleted and a new one is created:
strapi.entityService.update('api::article.article', 1, {
data: {
myDynamicZone: [
{
// will update
id: 2,
__component: 'compo.type',
foo: 'bar',
},
{
// will add a new & delete old ones
__component: 'compo.type2',
foo: 'bar2',
},
],
},
});
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17