0

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"}"

Ahmed
  • 49
  • 2
  • 9
  • Do you have a "Validation Document Update" function defined in a design document? – Juanjo Rodriguez Mar 26 '19 at 11:51
  • @JuanjoRodriguez From where can I check for these in Fauxton? – Ahmed Mar 26 '19 at 13:42
  • 1
    @Ahmed With the lack of documentation of the library that you're using, it's hard to tell how it should be used! Update validation are in the design docs of your database (if you ever put some). I'm maintaining this library(https://github.com/PHP-on-Couch/PHP-on-Couch). This one alteast is documented! – Alexis Côté Mar 26 '19 at 14:04

1 Answers1

0

I went with PHP-on-Couch and it worked perfectly.

Ahmed
  • 49
  • 2
  • 9