Skip to main content

REST API: Create & Update

How to create enteries trough the REST API

💡 Tip

Strapi takes advantage of the ability of the qs library to parse nested objects to create more complex queries.

Use qs directly to generate complex queries instead of creating them manually. Examples in this documentation showcase how you can use qs.

You can also use the interactive query builder if you prefer playing with our online tool instead of generating queries with qs on your machine.

Create

Create a Component

Creates a document and returns its value.

By default, a document is created with a published status. To create a document as a draft, pass the status query parameter with the value draft (e.g., ?status=draft).

If the Internationalization (i18n) feature is enabled on the content-type, it's possible to use POST requests to the REST API to create localized documents.

✏️ Note

While creating a document, you can define its relations and their order (see Managing relations through the REST API for more details).

Example request

POST http://localhost:1337/api/restaurants

{ 
"data": {
"Name": "Restaurant D",
"Description": [ // uses the "Rich text (blocks)" field type
{
"type": "paragraph",
"children": [
{
"type": "text",
"text": "A very short description goes here."
}
]
}
]
}
}
Example response
{
"data": {
"documentId": "bw64dnu97i56nq85106yt4du",
"Name": "Restaurant D",
"Description": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"text": "A very short description goes here."
}
]
}
],
"createdAt": "2024-03-05T16:44:47.689Z",
"updatedAt": "2024-03-05T16:44:47.689Z",
"publishedAt": "2024-03-05T16:44:47.687Z",
"locale": "en"
},
"meta": {}
}

Dynamic zones

Blocks

Update

Components

Create a Dynamic Zone

Example request

PUT http://localhost:1337/api/restaurants/hgv1vny5cebq2l3czil1rpb3?populate[myDynamicZone]=*

{ 
"data": {
"Name": "Restaurant D",
"myDynamicZone": [ // uses the "Dynamic zone" field type (This dynamic zone is named "myDynamicZone")
{
"__component": "compo.foo",
"foo": "this is foo",
},
{
"__component": "compo.bar",
"bar": "this is bar",
},
],
}
}

JavaScript query (built with the qs library):

The query URL above was built using the qs library. qs can be run locally on your machine, as shown in the following code example, or you can use our interactive query builder online tool.

const qs = require('qs');
const query = qs.stringify({
populate: {
myDynamicZone: "*"
},
}, {
encodeValuesOnly: true, // prettify URL
});

await request(`/api/restaurants/hgv1vny5cebq2l3czil1rpb3?${query}`);
Example response
{
"data": {
"documentId": "hgv1vny5cebq2l3czil1rpb3",
"Name": "Restaurant D",
"myDynamicZone": [
{
"__component": "compo.foo",
"id": "1",
"foo": "this is foo",
},
{
"__component": "compo.bar",
"id": "1",
"bar": "this is bar",
},
],
"createdAt": "2024-03-05T16:44:47.689Z",
"updatedAt": "2024-03-05T16:44:47.689Z",
"publishedAt": "2024-03-05T16:44:47.687Z",
"locale": "en"
},
"meta": {}
}

Blocks