1

As per Couchbase Sync-Gateway REST API documentation here below mentioned cURL should create a document in the specified database.

Below is the generated cURL from Postman.

curl -X PUT -H "Cache-Control: no-cache" -H "Postman-Token: 498d0fb6-77ac-9335-2379-14258c6731c7" -d '' "http://192.168.244.174:4984/db/"

I also tried adding JSON to the body of the request.

But when I send the put request through Postman, instead of creating a new document, it tries to create a new database and the JSON response is

{
 "error": "Precondition Failed",
 "reason": "Database already exists"
}

Am I missing something or it was a bug? Is there any other way to create a document to sync gateway?

1 Answer 1

0

There is a mistake in the documentation.

As per documentation,

You can either specify the document ID by including the _id object in the request message body, or let the software generate an ID.

But Couchbase REST API does not seem to work like that (may be they are not updating their documentation regularly). You need to provide the id in the URL like /{db}/{id}.

The below cURL worked for me.

curl -X PUT -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: 75ab844e-5130-708e-69e9-e87f878108b4" -d '{"name": "xxx", "full_name": "xxx yyy"}' "http://192.168.244.174:4984/db/123"

JSON response is

{
  "id": "123",
  "ok": true,
  "rev": "1-9324dabc947fc963a754b113d1215ac3"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.