Hi Atlassian Community!
Today, I want to share a Python script that streamlines a common (yet critical) process for some teams: creating multiple tickets and dynamically setting the summary, description, or any other field.
I consider this can be beneficial, especially in cases where the content to dynamically inject can be large, for example, a list of customers or internal users.
The Solution
This simple script makes use of Jira REST API (Create Issue Endpoint) to create issues.
It also iterates through a predefined list of items and creates individual tickets for each, appending the item to the ticket summary (can be any other field).
This approach not only saves time but also ensures consistency when required.
Preparation
Before running the script, ensure you've installed the "requests" library in your Python environment. If you haven't, you can do so by simply running:
pip install requests
Script
import requests import json from requests.auth import HTTPBasicAuth from getpass import getpass url = "https://YOURCLOUDURL.atlassian.net/rest/api/3/issue" email = input("Enter your Jira email: ") api_token = getpass("Enter your Jira API token: ") auth = HTTPBasicAuth(email, api_token) headers = { "Accept": "application/json", "Content-Type": "application/json" } user_list = [
"User1 LastName1",
"User2 LastName2",
"User3 LastName3"] for user_name in user_list: summary_text = f"Creating this issue for the user: {user_name}" payload = json.dumps({ "fields": { "project": { "id": "10000" # Ensure to replace with your actual project ID }, "summary": summary_text, "issuetype": { "id": "10002" # Ensure this matches the ID for your desired issue type } } }) response = requests.post(url, data=payload, headers=headers, auth=auth) if response.status_code == 201: print(f"Ticket created successfully for {user_name}.") else: print(f"Failed to create ticket for {user_name}. Status code: {response.status_code}")
Considerations
https://YOURCLOUDURL.atlassian.net/rest/api/2/project/KEY
https://YOURCLOUDID.atlassian.net/jira/settings/issues/issue-types
Next to each issue type, click the 3-dotted button and Edit, the ID will be appended at the end of the URL
Depending on your requirements, you might need to add additional fields to the payload for the tickets to be created correctly. Refer to the Jira REST API documentation for more details on customizing fields
I'd love to read your thoughts, feedback, or any enhancements you believe can improve the script further.
Disclaimer:
While this script is designed to facilitate certain interactions with JIRA Software Cloud as a convenience, it is essential to understand that its functionality is subject to change due to updates to JIRA Software Cloud’s API or other conditions that could affect its operation.
Please note that this script is provided on an "as is" and "as available" basis without any warranties of any kind. This script is not officially supported or endorsed by Atlassian, and its use is at your own discretion and risk.
Cheers!
Delfino Rosales
Senior Cloud Support Engineer
Amsterdam, NL
0 comments