Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to get user stories information via API calls?

Harshad Hegde
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 16, 2025

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!

1 answer

1 accepted

3 votes
Answer accepted
Deivid Araujo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 16, 2025

Hi Harshad. Welcome to Atlassian Community!

 

It is not a permission issue, otherwise you would not be able to see the results in the browser.

I was able to reproduce your code in my envirorment and found that the issue is the authentication. The e-mail and token should be encoded in base64 before joining with the "Basic " string.

You should use like this:

import requests
import base64
from datetime import datetime, timedelta
from urllib.parse import quote
from os import getenv

JIRA_URL = "https://gsk-onyx.atlassian.net"
API_TOKEN = getenv("JIRA_API_TOKEN")
EMAIL = getenv("USER_EMAIL")
JIRA_ACCT_ID = getenv("JIRA_ACCT_ID")

today = datetime.now().strftime("%Y-%m-%d")
one_year_ago = (datetime.now() - timedelta(days=365)).strftime("%Y-%m-%d")

raw_jql_query = f'assignee="{JIRA_ACCT_ID}" AND updated >= "{one_year_ago}" AND updated <= "{today}"'
encoded_jql_query = quote(raw_jql_query)

auth_str = f"{EMAIL}:{API_TOKEN}"
b64_auth_str = base64.b64encode(auth_str.encode()).decode()

HEADERS = {
"Authorization": f"Basic {b64_auth_str}",
"Content-Type": "application/json"
}

def fetch_issues():
url = f"{JIRA_URL}/rest/api/3/search?jql={encoded_jql_query}&maxResults=100"
response = requests.get(url, headers=HEADERS)
return response.json()

# Example use
issues = fetch_issues()
print(issues)

 

Harshad Hegde
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 17, 2025

Thank you so much! That was it!

Deivid Araujo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 17, 2025

I'm glad to help. 

If you can accept my comment as the anwser, I would appreciate it.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events