Sync Gateway 1.3 API docs problem

Hey,

I’ve been implementing some Sync gateway API calls as part of my login flow (unrelated to _user) and I’m pretty sure there’s an error in the API docs.

At the top of this page, it says that the PUT/{db}/ endpoint will create a document. I was trying to use that endpoint to create some docs and have them assigned auto-generated IDs and was, at first, getting success, but with nothing actually created and no response JSON, and then a “database already exists error” (I’m honestly not sure what changed, I tried reproducing the first case and couldn’t). I was sending the request with the doc’s JSON as the request body .

Anyway, I’m now using CBLite to generate the doc IDs and then posting them to the server at the PUT /{db}/{docid} endpoint, and that’s working fine, but I’d like to know if I’m doing something wrong with the first endpoint, or if it’s an error in the docs (it also says that there is supposed to be an empty request body, which means there’s definitely and inconsistency somewhere).

Thanks

@sam.wilks92

For auto generated doc ID’s you need to use a POST, e.g. in curl:

curl -X POST http://localhost:4985/db/ -H "Content-Type: application/json" -d '{"foo":"bar"}'

Response will be similar to:

{"id":"6e785e11db67d86e4a5ea45039fdbf88","ok":true,"rev":"1-cd809becc169215072fd567eebd8b8de"}

Yeah, that documentation is wrong; thanks for pointing it out. (Attn @jamiltz)

PUT to /db isn’t allowed. (In CouchDB it creates a database, but SG doesn’t support that.) POST creates a new doc with an auto-generated ID, but of course you have to provide the doc body (minus the _id property.)