Hello, I’m new to this forum and new to creating automations related to JIRA. I think it’s something simple, but I can’t figure it out. I need to create a simple Python script that automates worklog to an issue. I’m using the WorklogPRO plugin and this is the script I’m using:
import requests
import json
from datetime import datetime
# Jira credentials and URL
jira_url = "http://jira.mycompany.com"
api_token = "***"
email = "myemail@mycompany.com"
# Worklog details
issue_key = "AP-123"
time_spent = "1h" # Time spent on the issue
comment = "Test"
started = datetime.now().strftime("%Y-%m-%dT%H:%M:%S.000+0000") # Current time in Jira format
time_spent_seconds = 3600 # Time spent in seconds
# Endpoint for adding worklog
worklog_url = f"{jira_url}/rest/api/3/issue/{issue_key}/worklog"
# Worklog data
worklog_data = {
"timeSpent": time_spent,
"comment": comment,
"started": started,
"timeSpentSeconds": time_spent_seconds,
}
# Headers for the request
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_token}"
}
# Make the request to add worklog
response = requests.post(
worklog_url,
headers=headers,
data=json.dumps(worklog_data)
)
# Check the response status
if response.status_code == 201:
print("Worklog added successfully.")
else:
print(f"Failed to add worklog. Status code: {response.status_code}")
I’m encountering a problem where the script correctly connects to JIRA, but it always returns status code 200 instead of 201. I can’t figure out where it goes wrong. I know there are some answers to similar questions on the internet, but I can’t find any solution that I could use for my problem. I guess that somehow script uses a GET request instead of POST but I can’t figure out where.
I would be very grateful for any help. Best regards.