I’m trying to update entries in my collection with PHP curl but I got 404 error every time.
$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.