1

earlier I asked the question and I got the theoretical solution but then I am trying to create a user it's giving me an error

curl -X PUT http://admin:password@localhost:5984/_users/org.couchdb.user:jan \
 -H "Accept: application/json" \ 
 -H "Content-Type: application/json" -d "{\"name\": \"jan\", \"password\": \"apple\", \"roles\": [], \"type\": \"user\"}"

{"error":"forbidden","reason":"Doc ID must be of the form org.couchdb.user:name"}

Juanjo Rodriguez
  • 2,103
  • 8
  • 19
sandesh Jadhav
  • 139
  • 1
  • 1
  • 6
  • Does this answer your question? [Creating regular users in CouchDB](https://stackoverflow.com/questions/3684749/creating-regular-users-in-couchdb) – RamblinRose May 24 '21 at 14:37

2 Answers2

1

I found the solution for this question by creating a document in _users database,

{ "_id":"org.couchdb.user":username, "name":"username", "type":"user", "roles":[], "password":"plaintext_password" }

and put this above content in that document

sandesh Jadhav
  • 139
  • 1
  • 1
  • 6
1

I think the problem is that the colon : must be URL encoded. (I figured this out by using browser dev tools to see what the UI request looks like.)

Note that the USERNAME goes both to the path and the body JSON.


# Here is an example command using cURL

echo -ne '{"name": "USERNAME", "type": "user","roles": [],"password": "PASSWORD"}' |\
  curl -X PUT "http://admin:ADMIN_PASS@127.0.0.1:5984/_users/org.couchdb.user%3AUSERNAME" -d @-

# And same with HTTPie, my favourite

echo -ne '{"name": "USERNAME", "type": "user","roles": [],"password": "PASSWORD"}' |\
  http PUT "http://admin:$COUCH_PASS@127.0.0.1:5984/_users/org.couchdb.user%3AUSERNAME"

Peter Lamberg
  • 8,151
  • 3
  • 55
  • 69