Created
November 17, 2025 18:49
-
-
Save skeltonmod/6c7b936c025db36b8fb9bf634b21d9c1 to your computer and use it in GitHub Desktop.
JiraITSM.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| from datetime import datetime, timedelta | |
| import urllib.parse | |
| import json | |
| def generate_weekdays(start_date, end_date): | |
| """Generate weekdays (excluding Saturdays and Sundays) between start and end dates""" | |
| current = start_date | |
| weekdays = [] | |
| while current <= end_date: | |
| if current.weekday() != 5 and current.weekday() != 6: # Exclude Saturdays and Sundays | |
| weekdays.append(current) | |
| current += timedelta(days=1) | |
| return weekdays | |
| def make_dtr_request(date, entry_type, session): | |
| """ | |
| Make an ITSM Date API request | |
| Args: | |
| date: datetime object for the entry date | |
| entry_type: 'time_in' or 'time_out' | |
| session: requests session object | |
| """ | |
| url = 'https://testorg.atlassian.net/servicedesk/customer/portal/14/create/10335' | |
| headers = { | |
| 'accept': '*/*', | |
| 'accept-language': 'en-US,en;q=0.9,fil;q=0.8,ceb;q=0.7', | |
| 'content-type': 'application/x-www-form-urlencoded;', | |
| 'dnt': '1', | |
| 'origin': 'https://testorg.atlassian.net', | |
| 'priority': 'u=1, i', | |
| 'referer': 'https://testorg.atlassian.net/servicedesk/customer/portal/14/group/25/create/10335', | |
| 'sec-ch-ua': '"Google Chrome";v="141", "Not?A_Brand";v="8", "Chromium";v="141"', | |
| 'sec-ch-ua-mobile': '?0', | |
| 'sec-ch-ua-platform': '"macOS"', | |
| 'sec-fetch-dest': 'empty', | |
| 'sec-fetch-mode': 'cors', | |
| 'sec-fetch-site': 'same-origin', | |
| 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36', | |
| 'x-b3-spanid': 'd085e56eb25d563f', | |
| 'x-b3-traceid': '60c2e4420dd84e0e89227b87244e5a43', | |
| 'x-requested-with': 'XMLHttpRequest' | |
| } | |
| # Set customfield_10263 based on entry type | |
| customfield_value = '10400' if entry_type == 'time_in' else '10401' | |
| # Format date for the API (assuming 9:00 AM for time in, 6:00 PM for time out) | |
| if entry_type == 'time_in': | |
| time_str = date.strftime('%Y-%m-%dT09:00') | |
| summary = f'Time In - {date.strftime("%B %d, %Y")}' | |
| else: | |
| time_str = date.strftime('%Y-%m-%dT18:00') | |
| summary = f'Time Out - {date.strftime("%B %d, %Y")}' | |
| # Prepare form data | |
| form_data = { | |
| 'priority': '3', | |
| 'summary': summary, | |
| 'customfield_10262': time_str, | |
| 'customfield_10263': customfield_value, | |
| 'customfield_10228': '', | |
| 'customfield_10002': '', | |
| 'atl_token': '8675e26efa4feecda499fe550c05e2e5bc8abac4_lin', | |
| 'projectId': '10120' | |
| } | |
| try: | |
| response = session.post(url, headers=headers, data=form_data, timeout=30) | |
| # Print detailed response information | |
| print(f" Response Status Code: {response.status_code}") | |
| print(f" Response Headers: {dict(response.headers)}") | |
| try: | |
| # Try to parse JSON response | |
| response_json = response.json() | |
| print(f" Response JSON: {json.dumps(response_json, indent=2)}") | |
| except: | |
| # If not JSON, print text | |
| print(f" Response Text (first 500 chars): {response.text[:500]}") | |
| return response | |
| except requests.exceptions.Timeout as e: | |
| print(f" ✗ TIMEOUT ERROR: Request timed out after 30 seconds") | |
| print(f" Details: {str(e)}") | |
| return None | |
| except requests.exceptions.ConnectionError as e: | |
| print(f" ✗ CONNECTION ERROR: Could not connect to server") | |
| print(f" Details: {str(e)}") | |
| return None | |
| except requests.exceptions.HTTPError as e: | |
| print(f" ✗ HTTP ERROR: {str(e)}") | |
| return None | |
| except requests.exceptions.SSLError as e: | |
| print(f" ✗ SSL ERROR: {str(e)}") | |
| return None | |
| except requests.exceptions.RequestException as e: | |
| print(f" ✗ REQUEST ERROR: {type(e).__name__}") | |
| print(f" Details: {str(e)}") | |
| return None | |
| except Exception as e: | |
| print(f" ✗ UNEXPECTED ERROR: {type(e).__name__}") | |
| print(f" Details: {str(e)}") | |
| return None | |
| def main(): | |
| start_date = datetime(2025, 10, 28) | |
| end_date = datetime(2025, 11, 10) | |
| print("DTR API Automation Script with Diagnostics") | |
| print("=" * 50) | |
| print(f"Date range: {start_date.strftime('%B %d, %Y')} to {end_date.strftime('%B %d, %Y')}") | |
| print("Excluding Saturdays and Sundays") | |
| print() | |
| # Generate weekdays | |
| weekdays = generate_weekdays(start_date, end_date) | |
| print(f"Processing {len(weekdays)} weekdays:") | |
| for day in weekdays: | |
| print(f" - {day.strftime('%A, %B %d, %Y')}") | |
| print() | |
| # Create a session to maintain cookies | |
| session = requests.Session() | |
| # You can get the cookies by right clicking an xhr request and clicking on copy as curl | |
| cookies = {} | |
| session.cookies.update(cookies) | |
| print("Session cookies loaded:") | |
| for key in cookies.keys(): | |
| print(f" - {key}") | |
| print() | |
| # Test connection first | |
| print("Testing connection to Atlassian...") | |
| try: | |
| test_response = session.get('https://testorg.atlassian.net', timeout=10) | |
| print(f"✓ Connection test successful (Status: {test_response.status_code})") | |
| except Exception as e: | |
| print(f"✗ Connection test failed: {type(e).__name__} - {str(e)}") | |
| print("This might indicate network issues or firewall blocking.") | |
| print() | |
| # Process each weekday | |
| results = [] | |
| for date in weekdays: | |
| date_str = date.strftime('%Y-%m-%d') | |
| print(f"Processing {date.strftime('%A, %B %d, %Y')}...") | |
| # Attempt to create a lot of time in request to to see if the curl cookies are working | |
| print(f" Making ITSM request...") | |
| response_in = make_dtr_request(date, 'time_in', session) | |
| if response_in: | |
| if response_in.status_code == 200: | |
| print(f" ✓ Request successful") | |
| results.append(f"{date_str} Time In: SUCCESS") | |
| else: | |
| print(f" ✗ Request failed") | |
| results.append(f"{date_str} Time In: FAILED ({response_in.status_code})") | |
| else: | |
| results.append(f"{date_str} Time In: NETWORK ERROR") | |
| # TEST THE TIME OUT BECAUSE IT BARELY WORKS WHEN PLUGGED INTO A SERVICE API | |
| print(f" Making Time Out request...") | |
| response_out = make_dtr_request(date, 'time_out', session) | |
| if response_out: | |
| if response_out.status_code == 200: | |
| print(f" ✓ Time Out successful") | |
| results.append(f"{date_str} Time Out: SUCCESS") | |
| else: | |
| print(f" ✗ Time Out failed") | |
| results.append(f"{date_str} Time Out: FAILED ({response_out.status_code})") | |
| else: | |
| results.append(f"{date_str} Time Out: NETWORK ERROR") | |
| print() | |
| # Summary | |
| print("=" * 50) | |
| print("SUMMARY") | |
| print("=" * 50) | |
| for result in results: | |
| print(result) | |
| print(f"\nTotal requests made: {len(results)}") | |
| successful = len([r for r in results if 'SUCCESS' in r]) | |
| print(f"Successful requests: {successful}") | |
| print(f"Failed requests: {len(results) - successful}") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment