I'm trying to update a CouchDB document using PHP, but I always get {"error":"forbidden","reason":"Invalid data"} when sending the PUT request. GET requests work fine.
I've used "Baachi/CouchDB" from https://github.com/Baachi/CouchDB and also followed the guide here https://cwiki.apache.org/confluence/display/COUCHDB/PHP.
GET requests work find and I'm able to retrieve documents, but when sending a PUT request I get the following response: {"error":"forbidden","reason":"Invalid data"}
$client = new \GuzzleHttp\Client(['base_uri' => 'http://user:pass@somehost:5984', 'http_errors' => false]);
$connection = new \CouchDB\Connection($client);
$database = $connection->xyzu;
$doc = [
'_id' => 'appointment_2_e7611236-eccd-4f5b-abc3-8396db285014',
'_rev' => '1-a8b63e52533f665d7bdc57aea2eadd35',
'status' => 'Scheduled'
];
$database->update('appointment_2_e7611236-eccd-4f5b-abc3-8396db285014',
$doc);
Second try:
$doc = [
'_id' => 'appointment_2_e7611236-eccd-4f5b-abc3-8396db285014',
'_rev' => '1-a8b63e52533f665d7bdc57aea2eadd35',
'status' => 'Scheduled'
];
$request = $couch->send('PUT', '/' . $message[dbName] . '/' .$message[patient], json_encode($doc));
I was expecting the document to be updated, I tried removing the _rev just to make sure I'm doing everything right, and I got Document Conflict, so it's correct. But when including the _rev I get back "forbidden": "invalid data"
I should be getting "{"ok":true,"id":"123","rev":"2039697587"}"