Contentful has only a PHP SDK for the Content Delivery API (ready only). I need to update a entry from my PHP code and I could not find any sample code in the documentation.
Im trying to use the REST API directly (https://www.contentful.com/developers/docs/references/content-management-api/#/reference/entries/entries-collection/create-an-entry), but having tons of problems to send the correct form data with fields.
Does anyone have a sample code of how I can update the title of a entry using the entry ID?
thanks
To update an entry in Contentful you need to supply a valid JSON payload with your request. Now this of course depends on how your specific entry and content type looks like but here's a working example of such a payload:
Note that you need to nest each field value with the locales that you wish to update.
As the Contentful API uses optimistic concurrency you also need to supply a header with the latest known version of the entry. For example:
This payload with the correct version header needs to be sent with a
PUT
request tohttps://api.contentful.com/spaces/<space_id>/entries/<entry_id>
Replace the
<space_id>
and<entry_id>
with your specific values.Note that this is different from the Content Delivery Endpoints which live at
https://cdn.contentful.com
Also keep in mind that to access the management endpoints you need a management access token. A delivery access token will not do. For more information about how to create and use a management token refer to the official documentation here: https://www.contentful.com/developers/docs/references/authentication/#the-content-management-api