Curl command to view sync gateway users

I am running the following command to create a user on sync gateway:

 PS C:\Program Files (x86)\Couchbase> curl -vX PUT http://localhost:4985/simpleandroidsync/_user/user --data ' {"name":"user", "password":"password", "admin_channels":["*"]} '

but I get no response returned in powershell to let me know if the user was created.

Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.

PS C:\Windows\system32> cd "C:\Program Files (x86)\Couchbase"
PS C:\Program Files (x86)\Couchbase> curl -vX PUT http://localhost:4985/simpleandroidsync/_user/user --data  {"name":"user", "password":"password", "admin_channels":["*"]}'
>>

Is this the correct command to create users and how can I check stored users in sync gateway?

Thanks

–EDIT–
I restarted powershell and now I get the following response:

PS C:\Windows\system32> curl -vX PUT http://localhost:4985/simpleandroidsync/_user/user --data '{"name":"user", "password":"password", "admin_channels":["*"]}'
*   Trying ::1...
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4985 (#0)
> PUT /simpleandroidsync/_user/user HTTP/1.1
> User-Agent: curl/7.40.0
> Host: localhost:4985
> Accept: */*
> Content-Length: 50
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 50 out of 50 bytes
< HTTP/1.1 400 Bad Request
< Content-Type: application/json
< Server: Couchbase Sync Gateway/1.00
< Date: Tue, 21 Apr 2015 07:07:23 GMT
< Content-Length: 117
<
{"error":"Bad Request","reason":"Invalid JSON: \"invalid character 'n' looking for beginning of object key string\""}* C
onnection #0 to host localhost left intact

Im not sure what is wrong with my JSON, can anyone point out my mistake?

Hi @Gareth_Price ,

It might be line breaks not parsed properly by sync gateway.
Can you try running this curl command on a single line? (if there’s enough space :p)
May be related to this issue https://github.com/couchbase/sync_gateway/issues/783

To check for users in the database you can use the admin UI:

  1. Open http://localhost:4985/_admin/ in the browser
  2. Choose the databse you created the users on http://cl.ly/image/0Q1j0e2u3m3q/Screen%20Shot%202015-04-21%20at%2011.24.52.png
  3. Select the Users at the top to see the list of users http://cl.ly/image/0s1C1c1E2X2b/Screen%20Shot%202015-04-21%20at%2011.25.41.png

James

Hi James

thanks for the response, I tried shortening the command so that it fits on one line but that didn’t help:

PS C:\Windows\system32> curl -vX PUT http://localhost:4985/chat/_user/u --data '{"name":"u","password":"p"}'
*   Trying ::1...
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4985 (#0)
> PUT /chat/_user/u HTTP/1.1
> User-Agent: curl/7.40.0
> Host: localhost:4985
> Accept: */*
> Content-Length: 19
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 19 out of 19 bytes
< HTTP/1.1 400 Bad Request
< Content-Type: application/json
< Server: Couchbase Sync Gateway/1.00
< Date: Tue, 21 Apr 2015 10:49:04 GMT
< Content-Length: 117
<
{"error":"Bad Request","reason":"Invalid JSON: \"invalid character 'n' looking for beginning of object key string\""}* C
onnection #0 to host localhost left intact

Hi Gareth,
Can you try running the command from the “cmd” (not PowerShell). Sometimes PowerShell needs ekstra escaping of parameters… perhaps that is the issue?

Thanks
Martin

Hi Martin

I did not know that, your post did help me resolve the issue using escaping . The following command works for me using powershell:

PS C:\Windows\system32>  curl -vX PUT http://localhost:4985/simpleandroidsync/_user/user --data '{\"name\":\"user\",\"
password\":\"password\"}'

Using the original command (without the escaping) did not work in cmd, I received the same error response as before.

Thanks to everyone who replied.

Hi Gareth_Price,
Glad that the extra escaping helped and did the trick :slight_smile:

Thanks
Martin