Python library for interacting with JIRA via REST APIs.
—
JIRA Service Desk functionality for customer request management and service desk operations. This enables automation of IT service management workflows and customer support processes.
Check if JIRA Service Desk is available and supported.
def supports_service_desk(self) -> bool:
"""
Check if JIRA Service Desk is supported on this instance.
Returns:
Boolean indicating Service Desk support
"""Usage example:
# Check Service Desk availability
if jira.supports_service_desk():
print("Service Desk is available")
# Proceed with Service Desk operations
else:
print("Service Desk is not available on this JIRA instance")Operations for managing Service Desk instances.
def service_desks(self) -> list[ServiceDesk]:
"""
Get all Service Desk instances.
Returns:
List of ServiceDesk objects
"""
def service_desk(self, id: str) -> ServiceDesk:
"""
Get a specific Service Desk by ID.
Parameters:
- id: Service Desk ID
Returns:
ServiceDesk object
"""Usage examples:
# Get all service desks
service_desks = jira.service_desks()
for desk in service_desks:
print(f"Service Desk: {desk.projectName} (ID: {desk.id})")
print(f"Key: {desk.projectKey}")
print(f"Links: {desk._links}")
# Get specific service desk
it_desk = jira.service_desk('1')
print(f"IT Service Desk: {it_desk.projectName}")Operations for managing Service Desk customers.
def create_customer(self, email: str, displayName: str) -> Customer:
"""
Create a Service Desk customer.
Parameters:
- email: Customer email address
- displayName: Customer display name
Returns:
Created Customer object
"""Usage examples:
# Create new customer
customer = jira.create_customer(
email='customer@example.com',
displayName='John Customer'
)
print(f"Created customer: {customer.displayName}")
print(f"Customer ID: {customer.accountId}")
# Create multiple customers
customers_data = [
{'email': 'alice@company.com', 'name': 'Alice Johnson'},
{'email': 'bob@company.com', 'name': 'Bob Smith'},
{'email': 'carol@company.com', 'name': 'Carol Wilson'}
]
for customer_data in customers_data:
customer = jira.create_customer(
email=customer_data['email'],
displayName=customer_data['name']
)
print(f"Created customer: {customer.displayName}")Operations for managing Service Desk request types.
def request_types(self, service_desk: str) -> list[RequestType]:
"""
Get request types for a Service Desk.
Parameters:
- service_desk: Service Desk ID
Returns:
List of RequestType objects
"""
def request_type_by_name(self, service_desk: str, name: str) -> RequestType:
"""
Get request type by name.
Parameters:
- service_desk: Service Desk ID
- name: Request type name
Returns:
RequestType object
"""Usage examples:
# Get all request types for a service desk
service_desk_id = '1'
request_types = jira.request_types(service_desk_id)
for req_type in request_types:
print(f"Request Type: {req_type.name}")
print(f"Description: {req_type.description}")
print(f"Issue Type: {req_type.issueTypeId}")
# Get specific request type by name
incident_type = jira.request_type_by_name(service_desk_id, 'Incident')
print(f"Incident request type ID: {incident_type.id}")
# Find request type for creating requests
access_request = jira.request_type_by_name(service_desk_id, 'Access Request')
if access_request:
print(f"Found Access Request type: {access_request.id}")Create customer requests (Service Desk tickets).
def create_customer_request(
self,
fields: dict = None,
prefetch: bool = True,
**fieldargs
) -> dict:
"""
Create a customer request in Service Desk.
Parameters:
- fields: Dictionary of field values
- prefetch: Whether to fetch the created request details
- **fieldargs: Field values as keyword arguments
Returns:
Created customer request dictionary
"""Usage examples:
# Create incident request
incident_request = jira.create_customer_request(
serviceDeskId='1',
requestTypeId='10001', # Incident request type ID
summary='System is down',
description='The main application server is not responding',
reporter={'name': 'customer@example.com'}
)
print(f"Created incident: {incident_request['issueKey']}")
# Create access request with custom fields
access_request = jira.create_customer_request(
serviceDeskId='1',
requestTypeId='10002', # Access request type ID
summary='Network access for new employee',
description='Please provide network access for John Doe',
reporter={'name': 'hr@company.com'},
customfield_10010='John Doe', # Employee name field
customfield_10011='Engineering' # Department field
)
# Create request with attachments
hardware_request = jira.create_customer_request(
serviceDeskId='1',
requestTypeId='10003',
summary='Laptop replacement request',
description='Current laptop is failing, need replacement',
reporter={'name': 'employee@company.com'}
)
# Add attachment to the request after creation
with open('hardware_specs.pdf', 'rb') as f:
jira.add_attachment(hardware_request['issueKey'], f)Automate common incident response workflows:
def create_incident_with_priority(summary, description, priority='Medium'):
"""Create incident with automatic priority assignment."""
# Map priority to appropriate request type
priority_map = {
'Critical': '10001', # Critical incident type
'High': '10002', # High priority incident type
'Medium': '10003', # Standard incident type
'Low': '10004' # Low priority incident type
}
request_type_id = priority_map.get(priority, '10003')
incident = jira.create_customer_request(
serviceDeskId='1',
requestTypeId=request_type_id,
summary=summary,
description=description,
priority={'name': priority}
)
# Auto-assign critical incidents
if priority == 'Critical':
jira.assign_issue(incident['issueKey'], 'on-call-engineer')
# Add internal comment for critical incidents
jira.add_comment(
incident['issueKey'],
'Critical incident - escalated to on-call engineer',
is_internal=True
)
return incident
# Create incidents with different priorities
critical_incident = create_incident_with_priority(
'Database server crashed',
'Primary database server is not responding',
'Critical'
)
routine_request = create_incident_with_priority(
'Password reset request',
'User needs password reset for email account',
'Low'
)Create multiple customers from a data source:
import csv
def bulk_create_customers(csv_file_path):
"""Create customers from CSV file."""
created_customers = []
with open(csv_file_path, 'r') as file:
reader = csv.DictReader(file)
for row in reader:
try:
customer = jira.create_customer(
email=row['email'],
displayName=row['display_name']
)
created_customers.append(customer)
print(f"Created customer: {customer.displayName}")
except Exception as e:
print(f"Failed to create customer {row['email']}: {e}")
return created_customers
# CSV format: email,display_name
# customer1@company.com,John Smith
# customer2@company.com,Jane Doe
customers = bulk_create_customers('new_customers.csv')Monitor and report on SLA compliance:
def check_sla_breaches(service_desk_id, hours_threshold=24):
"""Check for potential SLA breaches."""
# Search for open requests older than threshold
from datetime import datetime, timedelta
threshold_date = datetime.now() - timedelta(hours=hours_threshold)
threshold_str = threshold_date.strftime('%Y-%m-%d %H:%M')
# Search for requests approaching SLA breach
jql = f'''
project = "{service_desk_id}" AND
status not in (Resolved, Closed) AND
created <= "{threshold_str}"
ORDER BY created ASC
'''
at_risk_requests = jira.search_issues(jql)
for request in at_risk_requests:
hours_open = (datetime.now() - datetime.strptime(
request.fields.created[:19], '%Y-%m-%dT%H:%M:%S'
)).total_seconds() / 3600
print(f"Request {request.key}: Open for {hours_open:.1f} hours")
# Add internal comment about SLA risk
if hours_open > hours_threshold:
jira.add_comment(
request,
f'SLA ALERT: Request has been open for {hours_open:.1f} hours',
is_internal=True
)
return at_risk_requests
# Check for SLA breaches daily
at_risk = check_sla_breaches('SD', hours_threshold=24)
print(f"Found {len(at_risk)} requests at risk of SLA breach")Map request types to appropriate workflows:
# Get and cache request types for efficiency
def get_request_type_mapping(service_desk_id):
"""Create mapping of request type names to IDs."""
request_types = jira.request_types(service_desk_id)
return {rt.name: rt.id for rt in request_types}
# Use mapping for request creation
request_type_map = get_request_type_mapping('1')
# Create different types of requests
request_configs = [
{
'type': 'Hardware Request',
'summary': 'New laptop needed',
'description': 'Employee needs laptop for remote work'
},
{
'type': 'Software Request',
'summary': 'Adobe Creative Suite license',
'description': 'Designer needs Creative Suite access'
},
{
'type': 'Incident',
'summary': 'Email server issues',
'description': 'Users cannot send emails'
}
]
for config in request_configs:
if config['type'] in request_type_map:
request = jira.create_customer_request(
serviceDeskId='1',
requestTypeId=request_type_map[config['type']],
summary=config['summary'],
description=config['description']
)
print(f"Created {config['type']}: {request['issueKey']}")Integrate with customer portals and external systems:
def create_request_from_portal(portal_data):
"""Create Service Desk request from portal submission."""
# Validate required fields
required_fields = ['customer_email', 'summary', 'description', 'category']
for field in required_fields:
if field not in portal_data:
raise ValueError(f"Missing required field: {field}")
# Map portal categories to request types
category_mapping = {
'technical_issue': '10001',
'access_request': '10002',
'hardware_request': '10003',
'software_request': '10004'
}
request_type_id = category_mapping.get(
portal_data['category'],
'10001' # Default to technical issue
)
# Create the request
request = jira.create_customer_request(
serviceDeskId='1',
requestTypeId=request_type_id,
summary=portal_data['summary'],
description=portal_data['description'],
reporter={'name': portal_data['customer_email']}
)
# Add any attachments
if 'attachments' in portal_data:
for attachment_path in portal_data['attachments']:
with open(attachment_path, 'rb') as f:
jira.add_attachment(request['issueKey'], f)
return request
# Example portal submission
portal_submission = {
'customer_email': 'user@company.com',
'summary': 'Cannot access shared drive',
'description': 'Getting permission denied error when accessing \\\\server\\shared',
'category': 'technical_issue',
'attachments': ['error_screenshot.png']
}
request = create_request_from_portal(portal_submission)
print(f"Created request from portal: {request['issueKey']}")