1

I am trying create document in an existing bucket in CouchBase using N1QL query. I am using soapUI to send request to localhost CouchBase server. I used this link to gain knowledge http://developer.couchbase.com/documentation/server/4.5/n1ql/n1ql-rest-api/index.html

N1QL:
GET http://localhost:8093/query/service?statement = ?select * from beer use keys ["beername::abcc"] 

this works well to fetch doc

How can I do the same to post json data, creating new document.

I tried:

POST http://localhost:8093/query/service. 

In request body

INSERT INTO `beer` ( KEY, VALUE ) 
VALUES 
 ( 
"k001", 
{ "id": "01", "type": "airline"} 
 ) 
RETURNING META().id as docid, *;

I am getting

"Error processing json request"

Cœur
  • 37,241
  • 25
  • 195
  • 267

3 Answers3

1

From the N1QL documentation:

For POST requests, you can specify the parameters in the request body in URL-encoded format or JSON format.

So seems that you can't directly specify the statement in the request body, you've to put in URL-encoded format or as JSON like { "statement" : "select ..." }.

albciff
  • 18,112
  • 4
  • 64
  • 89
0

Just put the INSERT statment directly in the body of the request:

curl -v http://localhost:8093/query/service -d 'statement=INSERT INTO `beer` ( KEY, VALUE ) VALUES ( "k002", { "id": "01", "type": "airline"} ) RETURNING META().id as docid, *;'

Or in postman http client:

enter image description here

Milan
  • 265
  • 1
  • 5
  • 13