Couchbase V5.0 rest api problem with scripts ** CRITICAL **

Hi Couchbase,

We are experiencing some weird behavior on Bucket REST API after upgrading Couchbase 4.6.3 to 5.0. Documents created using Bucket API REST are stored empty.

We use some .bat and .sh scripts in order to populate our buckets right before we start doing stress testing and user driven tests. Each bucket on our Couchbase DB has its user account with specific access role. Still, we use the Administrator user to call Bucket REST API.

The next command is an example of one of many curl commands we fire from .bat and .sh scripts. This particularly example belongs to a Windows .bat script:

curl -i -k -u Administrator: -H “Content-Type: application/json” -X POST http://<cb_ip>:8091/pools/default/buckets/places/docs/ct:ZZ:en -d @city_unknown_en.json

city_unknown_en.json file:
{
“ctry”: “ZZ”,
“hash”: “ZZ”,
“locality”: “Unknown City/Locality”,
“adminareal2”: “Unknown Neighbourhood”,
“adminareal1”: “Unknown State/Province”,
“tp”: “ct”
}

curl request:

  • Trying <cb_ip>…
  • TCP_NODELAY set
  • Connected to <cb_ip> (<cb_ip>) port 8091 (#0)
  • Server auth using Basic with user ‘Administrator’

POST /pools/default/buckets/places/docs/ct:ZZ:en HTTP/1.1
Host: <cb_ip>:8091
Authorization: Basic
User-Agent: curl/7.53.1
Accept: /
Content-Type: application/json
Content-Length: 165

  • upload completely sent off: 165 out of 165 bytes

Couchbase response:
[]HTTP/1.1 200 OK
X-XSS-Protection: 1; mode=block
X-Permitted-Cross-Domain-Policies: none
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Server: Couchbase Server
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Date: Sun, 05 Nov 2017 17:37:56 GMT
Content-Type: application/json
Content-Length: 2
Cache-Control: no-cache,no-store,must-revalidate

Despite of the 200 OK message, when we try to query that document it returns empty:

Query Editor:
select ct.* from places ct use keys [‘ct:ZZ:en’]

Query Results:
[
{ }
]

And from Couchbase Web Console we see a strange warning message: “Editing of binary document is not allowed”.

And when querying directly using REST GET method:
http://<cb_ip>:8091/pools/default/buckets/places/docs/ct:ZZ:en
Response:
{“meta”:{“id”:“ct:ZZ:en”,“rev”:“25-14f441365a6900000000000002000006”,“att_reason”:“invalid_json”,“expiration”:0,“flags”:33554438},“base64”:""}

We suspect from the previous response that the Bucket API REST for creation/update of documents is receiving a json payload as binary and trying to store it as json (that’s why the invalid_json).

Questions:

  1. Which is the new JSON format to POST a new document?
  2. Are we missing a command flag?
  3. Do you have an example of how to do it right?

We are already in production so we need to figure the solution out as soon as possible. Thanks in advance!

Carlos

Hi. We finally could solve it. There was a change in the Bucket REST API for creation of documents. See:

  • In CB < 5.0 POST operation for document creation expects Content-Type:application/json. And payload being pure json.
  • In CB >= 5.0 it was changed to Content-Type:application/x-www-form-urlencoded. And payload being value=<json_content>

So for example using cURL the new way is:

curl -i -k -u Administrator: -H “Content-Type: application/x-www-form-urlencoded” -X POST http://<cb_ip>:8091/pools/default/buckets/places/docs/ct:ZZ:en --data–urlencode value@city_unknown_en.json

1 Like