curl example for creating a user

448 views
Skip to first unread message

Joel Saltzman

unread,
Feb 14, 2014, 11:01:23 AM2/14/14
to mobile-c...@googlegroups.com
I've been trying to create a user using curl but I haven't had any luck. What am I doing wrong?

I tried:
curl -X POST -u Administrator:mypass http://127.0.0.1:8091/beer-sample/_user/jens --data '{"name":"jens","email":"je...@someemail.com","password":"1234"}}'
I receive:
Not Found.

I also tried the admin port:
curl -X PUT http://127.0.0.1:4985/beer-sample/_user/jens --data '{"name":"jens","email":"jens@ someemail.com","password":"1234"}}'
I receive:
Failed connect to 127.0.0.1:4985; Connection refused

Jens Alfke

unread,
Feb 14, 2014, 11:30:10 AM2/14/14
to mobile-c...@googlegroups.com

On Feb 14, 2014, at 8:01 AM, Joel Saltzman <saltzm...@gmail.com> wrote:

> I tried:
> curl -X POST -u Administrator:mypass http://127.0.0.1:8091/beer-sample/_user/jens --data '{"name":"jens","email":"je...@someemail.com","password":"1234"}}'

Port 8091 is Couchbase Server, not the Sync Gateway.

> I also tried the admin port:
> curl -X PUT http://127.0.0.1:4985/beer-sample/_user/jens --data '{"name":"jens","email":"jens@ someemail.com","password":"1234"}}'
> I receive:
> Failed connect to 127.0.0.1:4985; Connection refused

"Connection refused" implies the gateway isn't running. (Tech support: "Is your computer turned on?" :)

Also, even after you start the gateway I think that request will be rejected (with a 400) because it's not declared as JSON. You'll need to add a "Content-Type: application/json" header. This gets somewhat awkward with curl; I much prefer httpie, which lets me write that as
http PUT :4985/beer-sample/_user/jens name=jens email=je...@someemail.com password=1234

(But if you stick with curl, it also lets you omit the "http://127.0.0.1" prefix of the URL. Saves a lot of typing in the long run!)
(Also, you can skip the "name=jens" part because the name's already specified in the URL.)

—Jens

PS: If something in the docs led you astray, please let us know where the problematic part is so we can clarify or fix it. Thanks!

Joel Saltzman

unread,
Feb 14, 2014, 12:11:52 PM2/14/14
to mobile-c...@googlegroups.com
Great thanks, I didn't realize I needed the sync gateway. I got it setup (created a memcached bucket called sync_gateway) and running.
./sync_gateway 
09:00:56.930144 Configured Go to use all 8 CPUs; setenv GOMAXPROCS to override this
09:00:56.930237 Opening db /sync_gateway as bucket "sync_gateway", pool "default", server <walrus:>
09:00:56.930314 Opening Walrus database sync_gateway on <walrus:>
09:00:56.930646 WARNING: Database "sync_gateway" sync function undefined; using default -- rest.(*ServerContext).AddDatabaseFromConfig() at server_context.go:196
09:00:56.930653 Starting profile server on 
09:00:56.930660 Starting admin server on 127.0.0.1:4985
09:00:56.932185 Starting server on :4984 ...

 Now when I put to the gateway (port 4985) I get:
{"error":"not_found","reason":"no such database \"default\""}

However, I definitely have a default bucket with no authentication

Joel Saltzman

unread,
Feb 14, 2014, 12:47:11 PM2/14/14
to mobile-c...@googlegroups.com
 ./sync_gateway -bucket beer-sample
now I can create users. Thanks again!

Jens Alfke

unread,
Feb 14, 2014, 12:54:55 PM2/14/14
to mobile-c...@googlegroups.com

On Feb 14, 2014, at 9:11 AM, Joel Saltzman <saltzm...@gmail.com> wrote:

 Now when I put to the gateway (port 4985) I get:
{"error":"not_found","reason":"no such database \"default\""}
However, I definitely have a default bucket with no authentication

* The default database name is "sync_gateway", not "default". (You'll see that logged on the 2nd line of output: "Opening db /sync_gateway …")
* With no command-line args, the Sync Gateway uses a trivial in-memory storage engine called "Walrus", not Couchbase Server. (Again, you'll see that on the 2nd line, "…server <walrus:>".)

The setup docs are here. We definitely recommend reading them.

—Jens

Joel Saltzman

unread,
Feb 14, 2014, 1:01:18 PM2/14/14
to mobile-c...@googlegroups.com
Yeah, after reading /$DB/_user/$name I thought sync_gateway was connecting to the server, had access to all buckets and using the sync_gateway bucket as temporary storage. I would then be able to make calls to CRUD in any bucket. I now understand how it doesn't work that way. It connects and syncs to one bucket.

Jens Alfke

unread,
Feb 14, 2014, 1:07:04 PM2/14/14
to mobile-c...@googlegroups.com

On Feb 14, 2014, at 10:01 AM, Joel Saltzman <saltzm...@gmail.com> wrote:

I now understand how it doesn't work that way. It connects and syncs to one bucket.

…and that bucket should be treated as the gateway's private storage (with some very limited exceptions). If you modify docs in that bucket using Couchbase Server APIs, you will corrupt the metadata and confuse the gateway.

—Jens

Joel Saltzman

unread,
Feb 14, 2014, 1:08:50 PM2/14/14
to mobile-c...@googlegroups.com
Good to know. Thanks Jens
Reply all
Reply to author
Forward
0 new messages