How to edit post over API

i am using php/curl to push data , how can i edit an exiting data over api?

If you go to API and then open the REST-API playground, you can do this by hand.

Here’s what I did. Of course, you only need to run step 3 and 4, but this may help you or others:

  1. Enter the API key of your user - remember this is a very private thing
  2. GET the item you want to change, so you get the JSON data for it. You could use GET /content/items/{model}
  3. Copy the JSON code you want, paste it under POST /content/item/{model} and edit it to your liking. It’s important to pass at least the _id field, as without it you’re creating a new entry. You can leave any other field out if it doesn’t need changing, but it also works fine if you pass all fields - whatever you fancy.
  4. Click TRY and the record of your choosing has been updated :+1:

In my POST example, I used the following data. With this, only the title field in my collection gets changed (of the record that has this _id):

{
  "data": {
    "title": "This is the new title",
    "_id": "7f09435e663935167a0001e0"
  }
}

The curl command looks like this (mind you that test is the name of my collection here :wink:):

curl -X POST "https://your.host/cockpit/api/content/item/test" \
 -H "api-key: *****************" \
 -H "Content-Type: application/json" \
 -d '{"data":{"title":"This is the new title","_id":"7f09435e663935167a0001e0"}}'

Hope this helps!

3 Likes

wow, its really simple. I was just overcomplicating unnecessarily.