Function
def enable_project(host_url, username, password, project_key):
"""
This method is used to enable a project in Requirements.
Template parameters:
[project_key] is the project that will be enabled in Requirements
"""
# The REST API path to enable a project in Requirements
path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/projects/enable/' + project_key
# Send a POST request to enable the project
# return the result of the POST request
try:
return requests.post(host_url + path_uri, auth=HTTPBasicAuth(username, password))
except requests.exceptions.RequestException as e:
print e
Main
# ['SC'] project key parameter for the project to be enabled
# Store the result of the POST request to [response]
response = enable_project(HOST_URL, USERNAME, PASSWORD, 'SC')
# Check the response if project was enabled
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)
# Grab specific data from the JSON response
print 'Project enabled:', json_object['success']
print 'Project Name:', json_object['prjName']
print 'Issue Count:', json_object['issueCount']
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
{
"prjName": "Sand Castle",
"issueCount": 3,
"success": true,
"prjKey": "SC"
}
Project enabled: True
Project Name: Sand Castle
Issue Count: 3