Create & update content items
Prepr REST API lets you create and modify your content by sending POST
or PUT
requests to the following endpoints:
https://api.eu1.prepr.io/content_items
https://api.eu1.prepr.io/content_items/{id}
The data needs to be sent as JSON so please ensure the header of your request is set to the application/json
content type. If the JSON is invalid, the REST API will ignore the whole input.
Important
Make sure to create an access token with the scopes content_items
and content_items_publish
and bind a user to this token under Settings > Access tokens.
Please note that access tokens with write permissions must not be visible client-side. Read more in Authentication.
Content Item object
The Content Items object contains metadata about your content, such as an underlying model, the language version, or the publication date. For more details, please refer to the table below.
Argument | Type | Required | Description | |
---|---|---|---|---|
POST | PUT | |||
model |
Array | true | false | Defines ContentModel so the fields and validators are based on that model. |
locales |
Array | true | true | Defines a content item language version. |
items |
Array | true | false | Defines all field types of your content item (based on your ContentModel structure). |
status |
Array | false | false | Defines a content item status. |
slug |
Array | false | false | Defines the slug. Prepr auto-generates a unique slug unless this feature is disabled. For more details, check out Slug field type. |
publish_on |
Array | false | false | Defines when a content item needs to be published. |
expire_on |
Array | false | false | Defines when a content item needs to be unpublished. |
items
Sub-fields of The items
array contains subarrays of the content per locale
. So the key of each subarray is a locale
specified in en-US
format.
The list of field types in the items
array depends on the content model and must be specified per locale. Every field type has its own api_id
which can be found by navigating to Schema > Model > Field type settings. For a specification of the fields, please see Field types.
{
"items": {
"{{locale}}" : {
"{{api_id}}" : {
... // For a specification of the fields, see Field types.
}
}
}
}
Example query
{
"locales": [
"nl-NL"
],
"model": {
"id": "f401fff2-aaf2-45a4-b8fb-d84e8253557f"
},
"status": {
"nl-NL": {
"body": "Done"
}
},
"slug": {
"nl-NL": "/news-article-1"
},
"publish_on": {
"nl-NL": "1600262640"
},
"expire_on": {
"nl-NL": null
},
"items": {
"{{locale}}": {
"{{api_id}}": {
...
},
"{{api_id}}": {
...
}
}
}
}
Create a content item
Use HTTP POST to create a new content item. Once the request is successfully submitted, an auto-generated ID of the newly created content item will be returned as part of the response to this HTTP request.
POST: /content_items
Please note if you want a content item to be published immediately, you must send the "Done" status together with the current or past publication date as an integer timestamp in the UTC time format. Please see an example below.
The status code "201" will be returned if the request is successful.
{
"locales": [
"nl-NL"
],
"model": {
"id": "f401fff2-aaf2-45a4-b8fb-d84e8253557f"
},
"status": {
"nl-NL": {
"body": "Done"
}
},
"publish_on": {
"nl-NL": 1600262640
},
}
Update a content item
Use HTTP PUT to update an existing content item. You need to pass the ID of the content item to be updated.
Please note Prepr doesn't merge content changes but completely updates a content item per specified locale. So you must send the entire body per locale. For example, when you update the nl-NL
locale, the en-US
locale stays unchanged.
Although, it is possible to update the status
, publish_on
and expire_on
dates of a locale without sending the items array.
PUT: /content_items/{id}
Tip
Prepr can automatically generate and send events to your webhook once there are updates to content items. Read more on how to use webhooks.