Update an Entry
This endpoint updates an existing content entry. It supports two different methods: PUT for full replacement and PATCH for partial updates.
Endpoint
[PUT/PATCH]
/{collection_slug}/{entry_uuid}Permissions
This endpoint requires a token with the update ability.
Path Parameters
| Name | Required | Description |
|---|---|---|
collection_slug | Yes | The unique slug of the collection. |
entry_uuid | Yes | The unique identifier of the entry to update. |
Headers
| Name | Required | Description |
|---|---|---|
Accept | Yes | Specifies the response content type. Must be application/json. |
Authorization | Yes | Required. Must be a Bearer token with update scope. |
project-id | Yes | The unique identifier for the project. |
PUT vs. PATCH
PUT: Replaces the entire entry'sdataobject. Any fields you do not provide in thedataobject will be removed.PATCH: Updates only the fields you provide in thedataobject. All other fields will remain unchanged.
Body Parameters
The request body should be a JSON object containing the entry's data.
| Name | Type | Required | Description |
|---|---|---|---|
data | object | Yes | An object where keys are the field names and values are the new content. |
status | string | No | The publication status. Can be published or draft. If omitted, it is unchanged. |
locale | string | No | The locale code for the content. If omitted, it is unchanged. |
Relation and Media Reference Rules
- Relation and media fields accept entry/asset UUIDs (and numeric IDs when enabled by your setup).
- Every referenced entry/asset must belong to the same project as the request.
- Relation fields must also match the relation field's configured target collection.
- Invalid references return
422validation errors underdata.<field_name>.
Example Requests (PATCH)
This example updates only the title and changes the status to published.
import { createClient } from '@elmapicms/js-sdk';
const client = createClient(
'https://your-domain.com/api',
'YOUR_API_TOKEN',
'YOUR_PROJECT_UUID'
);
// Partial update using PATCH (only updates provided fields)
const updatedEntry = await client.patchEntry('blog-posts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', {
state: 'published',
data: {
title: 'An Updated Title for the Post'
}
});
// Full update using PUT (replaces entire data object)
const fullyUpdatedEntry = await client.updateEntry('blog-posts', 'a1b2c3d4-e5f6-7890-1234-567890abcdef', {
state: 'published',
data: {
title: 'An Updated Title for the Post',
slug: 'updated-slug',
content: 'Full content replacement'
}
});const collectionSlug = 'blog-posts';
const entryUuid = 'a1b2c3d4-e5f6-7890-1234-567890abcdef';
const partialUpdate = {
data: {
title: 'An Updated Title for the Post'
},
status: 'published'
};
axios.patch(`https://your-domain.com/api/${collectionSlug}/${entryUuid}`, partialUpdate, {
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_API_TOKEN', // Required - must have 'update' ability
'project-id': 'YOUR_PROJECT_UUID'
}
});use Illuminate\Support\Facades\Http;
$partialUpdate = [
'data' => ['title' => 'An Updated Title for the Post'],
'status' => 'published'
];
$response = Http::withToken('YOUR_API_TOKEN')->withHeaders([
'Accept' => 'application/json',
'project-id' => 'YOUR_PROJECT_UUID'
])->patch("https://your-domain.com/api/blog-posts/a1b2c3d4...", $partialUpdate);import React, { useState } from 'react';
function UpdateEntryForm({ collectionSlug, entryUuid }) {
const [title, setTitle] = useState('An Updated Title');
const handleUpdate = async () => {
try {
const response = await fetch(`https://your-domain.com/api/${collectionSlug}/${entryUuid}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_API_TOKEN', // Required - must have 'update' ability
'project-id': 'YOUR_PROJECT_UUID'
},
body: JSON.stringify({
data: { title },
status: 'published'
})
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.message || 'Update failed');
}
const updatedEntry = await response.json();
console.log('Update successful:', updatedEntry);
} catch (error) {
console.error('Failed to update entry:', error);
}
};
return <button onClick={handleUpdate}>Update Title & Publish</button>;
}<template>
<button @click="updateEntry">Update Title & Publish</button>
</template>
<script setup>
import { defineProps } from 'vue';
const props = defineProps({
collectionSlug: { type: String, required: true },
entryUuid: { type: String, required: true }
});
const updateEntry = async () => {
try {
const response = await fetch(`https://your-domain.com/api/${props.collectionSlug}/${props.entryUuid}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_API_TOKEN', // Required - must have 'update' ability
'project-id': 'YOUR_PROJECT_UUID'
},
body: JSON.stringify({
data: { title: 'A Vue-tifully Updated Title' },
status: 'published'
})
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.message || 'Update failed');
}
const updatedEntry = await response.json();
console.log('Update successful:', updatedEntry);
} catch (error) {
console.error('Failed to update entry:', error);
}
};
</script>curl -X PATCH "https://your-domain.com/api/blog-posts/a1b2c3d4..." \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "project-id: YOUR_PROJECT_UUID" \
-d '{
"data": { "title": "An Updated Title for the Post" },
"status": "published"
}'Responses
200: OK
Returns the updated content entry object.
{
"data": {
"uuid": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"locale": "en",
"published_at": "2023-10-29T14:00:00Z",
"fields": {
"title": "An Updated Title for the Post",
"slug": "api-best-practices" // This field was untouched
}
}
}403: Forbidden
Returned if the API token does not have the update ability.
{
"message": "API token doesn't have the right abilities!"
}404: Not Found
Returned if the collection or the entry does not exist.
{
"message": "Content not found."
}422: Unprocessable Entity
Returned for validation errors, such as providing an invalid value for a field or sending relation/media references outside the project or target collection.
{
"message": "The given data was invalid.",
"errors": {
"data.title": [
"The title must be at least 10 characters."
],
"data.related_item": [
"One or more relation references are invalid for this project or collection."
]
}
}