DEV Community

likayeltsova for flotiq

Posted on • Originally published at flotiq.com

1

Working with Content Objects in Flotiq headless CMS

Updating content through the API

There are two ways to update the content of an object:
PUT: When updating the object (PUT requests), all properties must be present in the request body, as the object data are replaced with the request body. The id property inside the object is ignored in PUT requests. Validation of update request works the same as in saving requests.
PATCH: When updating an object (a PATCH request), it is not necessary to specify all the properties of the object. The id property inside the object is ignored in PATCH requests. Validating the update request works the same as it does when saving requests.

Note
You will need to use your Application Read and write API KEY to perform this action or User API KEY scoped to accept update on the Content Type you wish to update. Read more about API keys and scoped API keys.

Updating Content Objects through the API

For a Content-Type defined according to the create Content Type example, a very simple PUT the payload can be sent to the supporting endpoint https://api.flotiq.com/api/v1/content/{name}/{id} to update Content Object:

  "title": "Object with changed title",
  "postContent": "This will be the new <b>content</b>"
}
Enter fullscreen mode Exit fullscreen mode
  • name is the name of the content type definition
  • id is the ID of the object to update

Example
CURL

curl --location --request PUT 'https://api.flotiq.com/api/v1/content/blogposts/blogposts-456712' \
--header 'X-AUTH-TOKEN: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--data-raw '{
    "title": "Object with changed title",
    "postContent": "This will be the new <b>content</b>"
}'
Enter fullscreen mode Exit fullscreen mode

Responses
200 OK
Returned when data has been correct, and the object was saved

    "id": "blogposts-456712",
    "internal": {
        "contentType": "blogposts",
        "createdAt": "2021-04-09T13:30:48+00:00",
        "updatedAt": "2021-04-09T13:30:48+00:00",
        "deletedAt": ""
    },
    "title": "Object with changed title",
    "postContent": "This will be the new <b>content</b>"
}
Enter fullscreen mode Exit fullscreen mode

Possible validation errors
Possible validation errors are the same as in creating Content Object; you can find the list here.

Batch update Content Objects through API

Updating up to 100 objects at once is described here, as batch creating and updating are done on the same API endpoint.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay