Update user info with Admin REST API

I’ve created user with admin api:

curl -X PUT http://my.server.address:4985/default/_user/myuser --data ‘{“email":"myuser@gmail.com”, “name”:“myuser”, “password”:“password”, “admin_channels”:[“myuser”, “public”]}’

How can I update user info?

curl -X PUT http://my.server.address:4985/default/_user/myuser --data ‘{“email":"myuser@gmail.com”, “name”:“myuser”, “password”:“NEW_password”, “admin_channels”:[“mouser”, “NEW_channel1”, “NEW_channel2” “public”]}’

Running the above command doesn’t give me any error but nor it updates the user info.
What Should I do?
Is it possible to add more info to the user document? like first name and age and…?

You’ve got the right commands there to update the user info. I ran the same and the user information was updated successfully.

Create user:

$ curl -iX PUT http://localhost:4985/default/_user/myuser --data '{"email":"myuser@gmail.com", "name":"myuser", "password":"password", "admin_channels":["myuser", "public"]}'
HTTP/1.1 200 OK
Server: Couchbase Sync Gateway/unofficial
Date: Wed, 07 Jan 2015 21:26:02 GMT
Content-Length: 0
Content-Type: text/plain; charset=utf-8

Update user:

$ curl -iX PUT http://localhost:4985/default/_user/myuser --data '{"email":"myuser@gmail.com", "name":"myuser", "password":"NEW_password", "admin_channels":["myuser", "public", "NEW_channel"]}'
HTTP/1.1 200 OK
Server: Couchbase Sync Gateway/unofficial
Date: Wed, 07 Jan 2015 21:26:08 GMT
Content-Length: 0
Content-Type: text/plain; charset=utf-8

Get user (to validate channel updates):

$ curl -iX GET http://localhost:4985/default/_user/myuser
HTTP/1.1 200 OK
Server: Couchbase Sync Gateway/unofficial
Date: Wed, 07 Jan 2015 21:26:18 GMT
Content-Length: 148
Content-Type: text/plain; charset=utf-8

{"name":"myuser","admin_channels":["NEW_channel","myuser","public"],"all_channels":["!","NEW_channel","myuser","public"],"email":"myuser@gmail.com"}

Get session for user (to validate password update):

$ curl -H "Content-Type:application/json" -iX POST http://localhost:4984/default/_session --data '{"name":"myuser","password":"NEW_password"}'
HTTP/1.1 200 OK
Content-Length: 143
Content-Type: application/json
Server: Couchbase Sync Gateway/unofficial
Set-Cookie: SyncGatewaySession=2cf8a0e81c86bbbe44f82790bf06ad2d7e9864df; Path=/default/; Expires=Thu, 08     Jan 2015 21:26:29 UTC
Date: Wed, 07 Jan 2015 21:26:29 GMT

{"authentication_handlers":["default","cookie"],"ok":true,"userCtx":{"channels":   {"!":1,"NEW_channel":6,"myuser":4,"public":4},"name":"myuser"}}

To your second question - if you’re looking to add more info to the user document, the usual approach is to define your own user_profile type document to track the additional information,

1 Like