# Api/collections/save 404 error PHP curl

**URL:** <https://discourse.getcockpit.com/t/api-collections-save-404-error-php-curl/2153>\
**Category:** Support\
**Created:** [November 25, 2021, 9:26am UTC](https://discourse.getcockpit.com/t/api-collections-save-404-error-php-curl/2153 "2021-11-25T09:26:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ciekals11](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/ciekals11/32/963_2.png) [@ciekals11](https://discourse.getcockpit.com/u/ciekals11)\
**Post date:** [November 25, 2021, 9:26am UTC](https://discourse.getcockpit.com/t/api-collections-save-404-error-php-curl/2153/1 "2021-11-25T09:26:38Z")

</div>

I’m trying to update entries in my collection with PHP curl but I got 404 error every time.

```php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, APP_URL . '/api/collections/save/trigocms?token=' . APP_TOKEN);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, ['Content-Type' => 'application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['data' => $site]));
$output = curl_exec($ch);
curl_close($ch);

```

`$site` is an associative array with this structure:  
[  
“\_id” =\> string  
“active” =\> boolean  
“address” =\> string  
“key” =\> string  
]

whole entry has few more fields but I want to update only those 3.  
Adding whole entry (with every field filled) does not work either.  
`PUT` method returns same error but loads longer for some reason.  
`APP_URL` and `APP_TOKEN` are declared in global scope and concatenated url is valid at the runtime.

_ **UPDATE** _  
After some debugging I have found that in `/modules/Collections/Controller/RestApi.php` in `save` method `$this->module('cockpit)->getUser();` returns `false` and `$this->param('data', null);` returns `null` for some unknown reason.

Most puzzling is that `$this->param('data', null);` returns `null`.  
when I dumped whole request object there is my json but not parsed. just plane json string.  
 ![Zrzut ekranu 2021-11-26 o 09.20.46](https://canada1.discourse-cdn.com/flex030/uploads/getcockpit/original/1X/85a24dfc9c73afb7eff831b528848a26a2154876.png)

---

<div class="post-metadata">

**Author:** ![ciekals11](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/ciekals11/32/963_2.png) [@ciekals11](https://discourse.getcockpit.com/u/ciekals11)\
**Post date:** [November 26, 2021, 8:36am UTC](https://discourse.getcockpit.com/t/api-collections-save-404-error-php-curl/2153/2 "2021-11-26T08:36:44Z")

</div>

After some extensive debugging I have found a solution.

My error was in curl. More specifically in the way that I tried to set headers.

I had to change:

```php
curl_setopt($ch, CURLOPT_HEADER, ['Content-Type' => 'application/json']);

```

to:

```php
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);

```
