How to add users to Bitbucket Server using Rest API

Still need help?

The Atlassian Community is here for you.

Ask the community

Because every environment is different there will be a few assumptions made in this example. If the assumptions are not true in the environment that the API will be run then you may need to make modifications or you will get errors. The script example is provided as is and is not guaranteed meet all possible situations. The script provided is meant only as an example and is not formally supported.


Adding many users to the Internal Bitbucket Server Directory is a task that is easier to accomplish with the REST API rather than trying to manually add each user one at a time via the UI

The purpose of this KB is to provide a working example of how to import a large number of users. 


  1. Bitbucket Server is running on localhost
  2. Bitbucket Server is running on HTTP using the default port
  3. Bitbucket Server is running with a context path called Bitbucket
  4. The Sys Admin user is defined as Admin
  5. The Sys Admin user password is defined as Admin

This would then be the URL for accessing Bitbucket Server: http://localhost:7990/bitbucket

Add A User

  • curl to add a user to Bitbucket Server
    curl -u Admin:Admin -X POST -H "Content-Type: application/json" "http://localhost:7990/bitbucket/rest/api/1.0/admin/users?name=<USERNAME_TO_ADD>&password=<PASSWORD_FOR_USER>&displayName=<DISPLAY_NAME_FOR_USER>&emailAddress=<EMAIL_ADDRESS_FOR_USER>&addToDefualtGroup=true&notify=false"

    <USERNAME_TO_ADD> - is replaced with the user name that you want to add
    <PASSWORD_FOR_USER> - is replaced with the password the new user will use. The user can edit this password when they login but they will not be forced to change the password
    <DISPLAY_NAME_FOR_USER> - is replaced with the full name of the user that you are adding
    <EMAIL_ADDRESS_FOR_USER> - is replaced with the email address of the user that you are adding

    Working example
    curl -u Admin:Admin -X POST -H "Content-Type: application/json" "http://localhost:7990/bitbucket/rest/api/1.0/admin/users?name=Marty&password=P-ssw0rd&displayName=Marty%20Mouse&"
  • Below is an example data file and bash script for adding any number of users from a file with the name of users.txt

    marty P-ssw0rd Marty%20Mouse
    pluto P-ssw0rd1 Plutto%20Dog
    goofy P-ssw0rd2 Goofy%20Dog

    (Make sure there is no blank lines at the end of the file)
    case "$1" in
      "") echo "Usage: Admin_UserName Admin_Password"
      * ) USERNAME=$1;;
    if [ "$ABORT" == 'N' ]; then
      case "$2" in
        "") echo "Usage: Admin_UserName Admin_Password"
        * ) PASSWORD=$2;;
    if [ "$ABORT" == 'N' ]; then
      while read -r a b c d; do
        echo "User: $a"
        curl -u $USERNAME:$PASSWORD -X POST -H "Content-Type: application/json" "http://localhost:7990/bitbucket/rest/api/1.0/admin/users?name=$a&password=$b&displayName=$c&emailAddress=$d&addToDefualtGroup=true&notify=false"
      done < users.txt



Last modified on Feb 19, 2016

Was this helpful?

Provide feedback about this article
Powered by Confluence and Scroll Viewport.