# How to edit post over API

**URL:** <https://discourse.getcockpit.com/t/how-to-edit-post-over-api/2634>\
**Category:** Cockpit v2\
**Created:** [December 19, 2022, 4:24am UTC](https://discourse.getcockpit.com/t/how-to-edit-post-over-api/2634 "2022-12-19T04:24:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cryptospy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/cryptospy/32/1169_2.png) [@Cryptospy](https://discourse.getcockpit.com/u/Cryptospy)\
**Post date:** [December 19, 2022, 4:24am UTC](https://discourse.getcockpit.com/t/how-to-edit-post-over-api/2634/1 "2022-12-19T04:24:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![witsec](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/witsec/32/818_2.png) [@witsec](https://discourse.getcockpit.com/u/witsec)\
**Post date:** [December 19, 2022, 7:56am UTC](https://discourse.getcockpit.com/t/how-to-edit-post-over-api/2634/2 "2022-12-19T07:56:56Z")

</div>

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 👍

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`):

```auto
{
  "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 😉):

```auto
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!

---

<div class="post-metadata">

**Author:** ![Cryptospy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/cryptospy/32/1169_2.png) [@Cryptospy](https://discourse.getcockpit.com/u/Cryptospy)\
**Post date:** [December 20, 2022, 5:09pm UTC](https://discourse.getcockpit.com/t/how-to-edit-post-over-api/2634/3 "2022-12-20T17:09:25Z")

</div>

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