Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

A helpful guide to creating organizations in bulk

 

This workaround is designed to assist Jira Service Management (JSM) projects in exporting new organizations in bulk. At present, there are limitations, as creating multiple organizations in JSM via the REST API requires sending individual POST requests for each organization. The JSM Cloud REST API does not currently support the creation of multiple organizations in a single request. We understand the significance of this feature and have included an enhancement in our development backlog to improve this functionality.

Please be aware that this workaround requires scripting development. If you have any additional questions about implementing the Jira REST API with custom scripts, feel free to share your concerns in our Developer Community.

Workaround steps

To implement this idea, I utilized Python, due to the fact that Python is known for its readability and simplicity, which makes it accessible for both beginners and experienced developers. Also, this language can be particularly useful when writing scripts to interact with APIs.

1. Use this Jira REST API to create an organization by passing the name of the new organization. You can do this by querying the endpoint, for example:

POST https://your-domain.atlassian.net/rest/servicedeskapi/organization

data '{ "name": "Charlie Cakes Franchises" }'

This will establish a new organization called 'Charlie Cakes Franchises'.

2. With this in mind, we can use a Python script to made this process in a bulk:

 Please be aware that this will only create a new organization if it has a unique name. If an organization with the same name already exists, the script will disregard it.

import requests

# Jira Service Management Cloud base URL
base_url = "https://<your-instance>/rest/servicedeskapi"

# Your JSM Cloud API credentials
auth = ('email@example.com', 'api_token')

# List of organization names to create
organizations = ["OrgName1", "OrgName2"]

# Function to get the list of existing organizations
def get_existing_organizations():
    response = requests.get(f"{base_url}/organization", auth=auth)
    if response.status_code == 200:
        return response.json().get('values', [])
    else:
        print("Failed to retrieve existing organizations.")
        print(response.text)
        return []

# Get the list of existing organizations
existing_organizations = get_existing_organizations()

# Convert existing organization names to a set for easy lookup
existing_org_names = {org['name'] for org in existing_organizations}

for org_name in organizations:
    if org_name in existing_org_names:
        print(f"Organization '{org_name}' already exists.")
    else:
        response = requests.post(
            f"{base_url}/organization",
            json={"name": org_name},
            auth=auth
        )
        
        if response.status_code == 201:
            print(f"Successfully created organization: {org_name}")
            print(response.json())
        else:
            print(f"Failed to create organization: {org_name}")
            print(response.text)
You can also find the script above in my personal GitHub repository here. It also includes other useful scripts, including one for exporting issues along with internal comments.

This workaround functions as illustrated in the screen recording below. In this example, I create three new organizations:

1 comment

Yanelli Fátima De la Cruz Apaza
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 29, 2024

Hi @Bruno Altenhofen! Does the workaround import users into the organization or just clients outside of organizations?

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events