Forums

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

Issue while pulling JIRA API Data using Python

Rakesh Patil May 30, 2024

Hi All While pulling jira data i am getting below error msg.

TypeError: 'NoneType' object is not subscriptable


I am trying pull data for below json custom filed data 

"customfield_20590":{
"id": 1187,
"name": "Product owner"
},
code is working when when i dont use ["name"]
issue["fields"]["customfield_20590"]["name"]

 

# This code sample uses the 'requests' library:
# http://docs.python-requests.org
import requests
from requests.auth import HTTPBasicAuth
import json
import csv


def JiraBoard():
url = "https://jiratest.com/rest/api/2/search"

auth = HTTPBasicAuth("test", "password")

headers = {
"Accept": "application/json"
}

query = {
'jql': 'project = DM', "startAt":1,
"maxResults":20
}

response = requests.request(
"GET",
url,
headers=headers,
params=query,
auth=auth
)
issues =(response.json()["issues"])
for issue in issues:

print(
issue["key"],
issue["id"],
issue["fields"]["customfield_20590"]["name"]
)

JiraBoard()



I am trying pull issue["fields"]["customfield_20590"]["name"] values data.

1 answer

0 votes
Rudy Holtkamp
Community Champion
May 30, 2024

Hi @Rakesh Patil ,

You better use the atlassian python lib (pip install atlassian-python-api) and use this:

from atlassian import Jira

def JiraBoard():
jira = Jira(
url='https://jiratest.com',
username='test',
password='password'
)

jql = 'project = DM'
start_at = 1
max_results = 20

response = jira.jql(jql, start=start_at, limit=max_results)

issues = response['issues']
for issue in issues:
custom_field = issue['fields'].get('customfield_20590')
custom_field_name = custom_field.get('name') if custom_field else 'N/A'

print(
issue['key'],
issue['id'],
custom_field_name
)

JiraBoard()

 

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, mindful member, mindful member badge, atlassian community, community kudos, community giveaway, atlassian swag, community values, empathy and kindness, badge challenge, atlassian learning, community engagement, swag giveaway

Earn a Badge, Win a Prize 🎁

Earning the Mindful Member badge proves you know how to lead with kindness, plus it enters you into a giveaway for exclusive Atlassian swag. Take the quiz, grab the badge, and comment on our announcement article to spread the good vibes!

Start here
AUG Leaders

Atlassian Community Events