Content Objects
Some resources in the Plate API include a dynamic set of content fields. These are defined in the Plate Dashboard and are specific to certain resource types, such as:
- Site Translations
- Posts
- Sections
- Elements
Resources with customizable content fields are referred to as content objects. These objects have special handling in both requests and responses.
Responses for Content Objects
When retrieving a content object (e.g., via GET), the response includes a content section inside the attributes object. This contains all defined content fields for that object.
Example response
{
"data": {
"id": 1,
"type": "elements",
"attributes": {
"content": {
"categories": {
"value": [789],
"type": "reference",
"subtype": "posts",
"content_field_id": 123
},
"name": {
"value": "Pied Piper",
"type": "string",
"content_field_id": 456
},
"some_link": {
"value": "https://www.example.com",
"type": "link",
"content_field_id": 789
}
},
...
}
}
}
How It Works
Each key inside the content object represents a dynamic content field for the resource. For each content field, the following properties are returned:
| Property | Description |
|---|---|
value | The value of the field (can be a string, integer, or array). |
type | Type of content field, e.g. "string", "reference", or "array". |
subtype (optional) | Further detail on the type, used with "reference" or "array" fields. |
content_field_id | The unique ID of the content field definition. |
Value Behavior by Type
- String/Integer fields return a simple value.
- Link fields return a string value with the URL.
- Reference fields return an array of IDs (e.g.,
[12, 23, 24]), referencing other resources.subtypeindicates the resource type, e.g., "posts".
- Array fields return an array of values.
- If
subtypeis"attachments", it's an array of attachment IDs. - If
subtypeis"text", it's an array of strings, which is the actual value of the content field.
- If
Requests for Content Objects
When creating or updating content objects (e.g., via POST or PUT), you can include values for dynamic content fields directly in the request payload.
Example Request
{
"data": {
"name": "A name for the new element",
"categories": [
{
"id": 25
},
{
"title": "A title for a newly created reference post"
*// additional fields for new post...*
}
],
"some_link": {
"url": "https://www.example.com"
}
}
}
How to Send Content Field Data
| Field Type | Format |
|---|---|
string, choice | Send the raw value ("Some Text" or 42). |
media | Send the ID of an existing attachment. |
link | Send an object with the following keys: { "url": "https://www.example.com" } Note that setting up links to actual posts or attachments in the site, is not yet supported in the V2 API. |
reference | Send an array of objects: |
- { "id": 25 } for referencing existing objects. | |
- { "title": "New Post" } for creating a new nested object inline. |
Nested references are supported. You can include the full data for referenced objects within the request, eliminating the need to create them in advance. In the request example, the field
categories(with typereference) will be set with two referenced objects. One existing object withid=25, and one new object which will have the value "A title for a newl...." for the content fieldtitle
Summary
- Content objects have dynamic fields defined in the Plate dashboard.
- These fields are returned under the content key in the response.
- When creating or updating content objects, field data can be submitted inline.
- The structure and format of each field depend on its type (string, reference, array, etc.).