DATA CENTER AND SERVER | CLOUD

Enable/Disable Project

Contents


Enable Project


The following code will enable a specific project in Requirements.

In this example, a project with the key 'SC' will be enabled, then grab the returned JSON response to print the returned values.  

 Click here to expand...
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


Disable a project


The following script will disable a specific project in Requirements.

In this example, a project with the key 'SC' will be disabled, then print the JSON response of the request.  

 Click here to expand...
Function
def disable_project(host_url, username, password, project_key):
    """
    This method is used to disable a project in Requirements.
    Template parameters:
    [project_key] is the project that will be disabled in Requirements
    """

    # The REST API path to disable a project in Requirements
    path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/projects/disable/' + project_key

    # Send a POST request to disable a project in the Requirements
    # 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 disabled
# Store the result of the POST request to [response]
response = disable_project(HOST_URL, USERNAME, PASSWORD, 'SC')

# Check response if project is disabled in Requirements
if response.status_code == 200:
    print response.text
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
{"prjKey":"SC","prjName":"Sand Castle","issueCount":3,"success":true}