How to add users to Bitbucket Server using Rest API

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

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.

Solution

Assumptions

  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

    1 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

    1 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&emailAddress=martym@yourdomain.com&addToDefualtGroup=true&notify=false"
  • Below is an example data file and bash script for adding any number of users from a file with the name of users.txt

    users.txt

    1 2 3 marty P-ssw0rd Marty%20Mouse martym@yourdomain.com pluto P-ssw0rd1 Plutto%20Dog plutod@yourdomain.com goofy P-ssw0rd2 Goofy%20Dog goofyd@yourdomain.com

    (Make sure there is no blank lines at the end of the file)

    AddUsers.sh

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #!/bin/bash ABORT="N" case "$1" in "") echo "Usage: AddUsers.sh Admin_UserName Admin_Password" ABORT="Y";; * ) USERNAME=$1;; esac if [ "$ABORT" == 'N' ]; then case "$2" in "") echo "Usage: AddUsers.sh Admin_UserName Admin_Password" ABORT="Y";; * ) PASSWORD=$2;; esac fi if [ "$ABORT" == 'N' ]; then clear 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 fi

Updated on April 15, 2025

Still need help?

The Atlassian Community is here for you.