Function
def add_issue_to_folder(host_url, username, password, project_key, folder_id, issue_key):
"""
This method is used to add an existing issue to a given folder
Template parameters:
[project_key] the project key
[folder_id] the folder ID
Query parameter
[issue_key] the key of the issue to be associated
"""
# The REST API path to add an issue on the specified folder
path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/tree/' + \
project_key + '/folderissue/' + folder_id + '?'
# The field-value pair/s that will be added to the query string
issue_key_field_value = 'issuekey=' + issue_key
# The query string to be added to the URI
query_string = issue_key_field_value
# Send a POST request to add an existing issue to a given folder
# Return the result of the POST request
try:
return requests.post(host_url + path_uri + query_string, auth=HTTPBasicAuth(username, password))
except requests.exceptions.RequestException as e:
print e
Main
def main():
# ['SC'] project key parameter where the issue will be added
# ['213'] folder id parameter of the folder where the issue will be added
# ['SC-196'] issue key parameter of the issue that will be added
# Store the result of the POST request to [response]
response = add_issue_to_folder(HOST_URL, USERNAME, PASSWORD, 'SC', '213', 'SC-196')
# Check response if baseline is created
if response.status_code == 200:
# Get the value of the JSON response and print in a readable JSON format
# json dumps formats the JSON string in readable format
json_object = json.loads(response.text)
print json.dumps(json_object, indent=4)
else:
print 'Error code: ', response.status_code
print response.text
Refer to Constant variable for information of the following constant variable: [HOST_URL, USERNAME, PASSWORD]
Output
{
"childReqs": {
"childReq": []
},
"issueId": 26238,
"description_html": "",
"rootfolderdescription": "",
"url": "https://addontest.sandbox.easesolutions.com/browse/SC-196",
"icon_url": "https://addontest.sandbox.easesolutions.com/images/icons/issuetypes/story.svg",
"summary": "As a team, we can finish the sprint by clicking the cog icon next to the sprint name above the \"To Do\" column then selecting \"Complete Sprint\" >> Try closing this sprint now",
"key": "SC-196",
"issueType": "Story",
"position": 1,
"id": 8786
}