I am trying to write some python code to get all tasks assigned to me on Jira for a specific time period. So far my code looks something like this:
# Jira Cloud instance URL
JIRA_URL = "https://xxxxxx.atlassian.net"
# API token and email for authentication (stored as environment variables)
API_TOKEN = getenv("JIRA_API_TOKEN")
EMAIL = getenv("USER_EMAIL")
JIRA_ACCT_ID = getenv("JIRA_ACCT_ID")
# Calculate today's date and last year's date dynamically
today = datetime.now().strftime("%Y-%m-%d")
one_year_ago = (datetime.now() - timedelta(days=365)).strftime("%Y-%m-%d")
# JQL query to fetch all issues updated in the last year assigned to current user
raw_jql_query = f"assignee={JIRA_ACCT_ID} AND updated >= \"{one_year_ago}\" AND updated <= \"{today}\""
encoded_jql_query = quote(raw_jql_query)
# Headers for authentication
HEADERS = {
"Authorization": f"Basic {EMAIL}:{API_TOKEN}",
"Content-Type": "application/json"
}
# Function to fetch issues
def fetch_issues():
url = f"{JIRA_URL}/rest/api/3/search?jql={encoded_jql_query}&maxResults=100"
response = requests.get(url, headers=HEADERS)
The credentials are correct and I do get a response:
Status Code: 200
Response Text: {"startAt":0,"maxResults":100,"total":0,"issues":[]}
When I physically go to the URL generated above, There is a lot of information under `issues` but the response gives me an empty list (as seen above). Is it a security reasoned block or am I missing something?
Thank you!