Couchbase Lite: 'not_found' error when doing PUT/POST using REST API


I’m currently developing an app using Couchbase Lite Beta2 for Android and Phonegap.
The Phonegap plugin is creating a database (let’s say ‘dbTest’) and inserting some documents using Couchbase Lite java API:

Manager server = new Manager(directory, Manager.DEFAULT_OPTIONS); Database database = server.getDatabase(DEFAULT_DATABASE_NAME); database.createDocument().putProperties(new java.util.HashMap(){{this.put("a1", "v1"); this.put("a2", "v2");}});

This works fine. I can even retrieve the inserted document from my webapp using the following REST CALL (mocked with curl):

curl -X GET -H 'Content-Type: application/json'


The problem is when I try to PUT or POST a new document using the REST API. No matter what I try, I always end up with the following error:

{"error":"not_found","reason":"Router unable to route request to do_PUT_Documentjava.lang.reflect.InvocationTargetException"}

The easiest way to replicate this error is using curl:

curl -X PUT -H ‘Content-Type: application/json’ -d “{‘x’:‘y’}”

My question is: Am I doing something wrong? I think this is a trivial usecase that should be supported by the current api, even if it’s in beta 2 stage. Given that this is my first time working with couchbase I assume I’m missing something obvious here.


Looks like you need to change the way you are quoting the fields. This worked for me:

curl -X PUT -H 'Content-Type: application/json' -d '{"x":"y"}'

When I tried to use your snippet, I could see the following error in the adb logcat output:

W/Database( 1233): WARNING: Exception parsing body into dictionary W/Database( 1233): org.codehaus.jackson.JsonParseException: Unexpected character (''' (code 39)): was expecting double-quote to start field name W/Database( 1233): at [Source: Acme.Serve.Serve$ServeInputStream@53568f3c; line: 1, column: 3] W/Database( 1233): at org.codehaus.jackson.JsonParser._constructError( W/Database( 1233): at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError( W/Database( 1233): at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar( W/Database( 1233): at org.codehaus.jackson.impl.Utf8StreamParser._handleUnusualFieldName( W/Database( 1233): at org.codehaus.jackson.impl.Utf8StreamParser._parseFieldName( W/Database( 1233): at org.codehaus.jackson.impl.Utf8StreamParser.nextToken( W/Database( 1233): at W/Database( 1233): at W/Database( 1233): at W/Database( 1233): at W/Database( 1233): at W/Database( 1233): at com.couchbase.lite.router.Router.getBodyAsDictionary( W/Database( 1233): at com.couchbase.lite.router.Router.do_PUT_Document( W/Database( 1233): at java.lang.reflect.Method.invokeNative(Native Method) W/Database( 1233): at java.lang.reflect.Method.invoke( W/Database( 1233): at com.couchbase.lite.router.Router.start( W/Database( 1233): at com.couchbase.lite.listener.LiteServlet.service( W/Database( 1233): at javax.servlet.http.HttpServlet.service( W/Database( 1233): at Acme.Serve.Serve$ServeConnection.runServlet( W/Database( 1233): at Acme.Serve.Serve$ServeConnection.parseRequest( W/Database( 1233): at Acme.Serve.Serve$ W/Database( 1233): at Acme.Utils$ThreadPool$ W/Database( 1233): at E/Database( 1233): Router unable to route request to do_PUT_Document E/Database( 1233): java.lang.reflect.InvocationTargetException E/Database( 1233): at java.lang.reflect.Method.invokeNative(Native Method) E/Database( 1233): at java.lang.reflect.Method.invoke( E/Database( 1233): at com.couchbase.lite.router.Router.start( E/Database( 1233): at com.couchbase.lite.listener.LiteServlet.service( E/Database( 1233): at javax.servlet.http.HttpServlet.service( E/Database( 1233): at Acme.Serve.Serve$ServeConnection.runServlet( E/Database( 1233): at Acme.Serve.Serve$ServeConnection.parseRequest( E/Database( 1233): at Acme.Serve.Serve$ E/Database( 1233): at Acme.Utils$ThreadPool$ E/Database( 1233): at E/Database( 1233): Caused by: com.couchbase.lite.CouchbaseLiteException E/Database( 1233): at com.couchbase.lite.router.Router.do_PUT_Document( E/Database( 1233): ... 10 more W/ThrottleService( 438): unable to find stats for iface rmnet0

JSON only allows double-quotes, not single quotes.
But the response from CBL should be more informative (at a minimum it should be a 400, not 404.)

I filed to improve the CBL Response in that case.

That was it! I knew it was my fault!
Agree with @jens, the error should be more informative than that!