# Error 404 on Save via API

**URL:** <https://discourse.getcockpit.com/t/error-404-on-save-via-api/920>\
**Category:** Support\
**Created:** [July 11, 2019, 7:19am UTC](https://discourse.getcockpit.com/t/error-404-on-save-via-api/920 "2019-07-11T07:19:18Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![metlock](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@metlock](https://discourse.getcockpit.com/u/metlock)\
**Post date:** [July 11, 2019, 7:19am UTC](https://discourse.getcockpit.com/t/error-404-on-save-via-api/920/1 "2019-07-11T07:19:18Z")

</div>

I note a few threads but no one seems to say how they fixed it! Any thoughts  
I can /get/ fine but as soon as I try and use /save/ i get a 404 error all the details look good (works to get)

Sample url: [https://sever/api/collections/save/PlayerStats?token=token&\_id=1&UID=3&Credits=1](https://sever/api/collections/save/PlayerStats?token=token&_id=1&UID=3&Credits=1)

Any ideas? I’ve tried on two different servers and get the same outcome.

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [July 11, 2019, 11:27am UTC](https://discourse.getcockpit.com/t/error-404-on-save-via-api/920/2 "2019-07-11T11:27:29Z")

</div>

You have to wrap your field names into `data`, so this should work:  
`/api/collections/save/PlayerStats?token=xxtokenxx&data[_id]=1&data[UID]=3`

See also: [https://getcockpit.com/documentation/api/collections](https://getcockpit.com/documentation/api/collections)

---

<div class="post-metadata">

**Author:** ![metlock](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@metlock](https://discourse.getcockpit.com/u/metlock)\
**Post date:** [July 11, 2019, 12:22pm UTC](https://discourse.getcockpit.com/t/error-404-on-save-via-api/920/3 "2019-07-11T12:22:43Z")

</div>

I get the same result error 404, any other ideas?

Could it be a htaccess issue? With no token provided i get “Unauthorised” but as soon as i supply the key it fails. Adding data[value] gave a 404 as well.

---

<div class="post-metadata">

**Author:** ![metlock](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@metlock](https://discourse.getcockpit.com/u/metlock)\
**Post date:** [July 12, 2019, 2:06pm UTC](https://discourse.getcockpit.com/t/error-404-on-save-via-api/920/4 "2019-07-12T14:06:51Z")

</div>

Tried again with a 3rd webserver this time on Lightsail, exactly the same result. If it’s not working with default setups via DO and Lightsail I would say this needs a look at in more detail. I can’t be the only one who hits a brick wall?

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [July 15, 2019, 2:28pm UTC](https://discourse.getcockpit.com/t/error-404-on-save-via-api/920/5 "2019-07-15T14:28:26Z")

</div>

> [@metlock](#):
>
> With no token provided i get “Unauthorised”

That’s by design. You always have to send an api key.

> [@metlock](#):
>
> this needs a look at in more detail

What’s your system (PHP \>7, Apache or nginx…)?  
Do you use the latest Cockpit version (next branch)?  
Which addons do you use?

---

<div class="post-metadata">

**Author:** ![metlock](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@metlock](https://discourse.getcockpit.com/u/metlock)\
**Post date:** [August 9, 2019, 7:38am UTC](https://discourse.getcockpit.com/t/error-404-on-save-via-api/920/6 "2019-08-09T07:38:40Z")

</div>

> [@raffaelj](#):
>
> &data[\_id]

PHP 7 with Apache via a Bitnami deployment on Lightsail.  
I’ve tried both the stable and edge release with the same result. Any attempt to call /save/ results in a 404 if a parameter is sent alongside the token.

No addons installed this is a clean install of cockpit

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [August 10, 2019, 9:25am UTC](https://discourse.getcockpit.com/t/error-404-on-save-via-api/920/7 "2019-08-10T09:25:55Z")

</div>

Maybe I understood your issue now. Do you try to save `_id=1` with the numeric “1” or is the “1” a placeholder for a mongodb id. It should look like this: `_id=5d271cab33386214e40002ad`.  
After I tried to save it with the numeric id, I got a 404 as well.

If you try to save a new entry, you don’t have to send a `_id` with your request. It will be generated automatically.

---

<div class="post-metadata">

**Author:** ![metlock](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@metlock](https://discourse.getcockpit.com/u/metlock)\
**Post date:** [August 12, 2019, 11:37am UTC](https://discourse.getcockpit.com/t/error-404-on-save-via-api/920/8 "2019-08-12T11:37:58Z")

</div>

this is not a MongoDB the ID=1 corresponds to a record I would like to update. I’ve also tried without an id as well and get a 404. It seems as any data is included in the url it throws a 404.

Give it a try spin-up an instance on Lightsail and use the standard install method not a docker and you will see what I mean. Same error on EC2 and Digital Ocean. I think the install info needs updating to include what ever this issue us.

---

<div class="post-metadata">

**Author:** ![metlock](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@metlock](https://discourse.getcockpit.com/u/metlock)\
**Post date:** [August 12, 2019, 11:46am UTC](https://discourse.getcockpit.com/t/error-404-on-save-via-api/920/9 "2019-08-12T11:46:45Z")

</div>

I see what you mean about the mongodb id so I’ve tried as follows and still get a 404

[https://domain/api/collections/save/PlayerStats?token&data[\_id]=15d26e5ee3035340a82000191&data[credits]=3](https://domain/api/collections/save/PlayerStats?token&data%5B_id%5D=15d26e5ee3035340a82000191&data%5Bcredits%5D=3)

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [August 13, 2019, 1:19pm UTC](https://discourse.getcockpit.com/t/error-404-on-save-via-api/920/10 "2019-08-13T13:19:59Z")

</div>

I don’t have the time right now to test Amazon Lightsail. Maybe I’ll give it a try in a few days, but I can’t promise.

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [August 13, 2019, 1:36pm UTC](https://discourse.getcockpit.com/t/error-404-on-save-via-api/920/11 "2019-08-13T13:36:51Z")

</div>

> [@metlock](#):
>
> I’ve tried both the stable and edge release

Do you mean the “next” branch? There is no “edge” - and “legacy” is outdated. I use always the next branch.

I want to be sure, that the issue is not only a typo…

Are you able to save a new entry via backend? It uses nearly the same code, so if that works, you have write permissions and it should work with the api, too.

Did you try to save a very simplified test collection, where you didn’t try to save entries with a numeric id in the preserved `_id` field?

Does Cockpit work on a local machine like expected?
