Forums

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

Jira API + Python

Thiago Portocarrero de Lima
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!
October 6, 2023

Hello!

By reading some other discussions here on the community, and in other sites, I've wrote a few python codes trying to get my Jira information into a dataframe and use it. Let me show some attempts:

#1

import requests
import json

url = 'https://URL.atlassian.net/rest/api/3/search?jql=project%20%3D%20PROJECTNAME%20ORDER%20BY%20updated%20DESC&maxResults=100&startAt=0&fields=*all,-comment'

header = {
"Autenticate": "TOKEN"
}

request = requests.get(url, headers=header)
resp = json.loads(request.content)
print(resp)

 

#2

from jira import JIRA

jira = JIRA(basic_auth=('USER', 'PASS'), options={'server':'https://URL.atlassian.net'})

def get_all_issues(jira_client, project_name, fields):
    issues = []
    i = 0
    chunk_size = 100
    while True:
        chunk = jira_client.search_issues(f'project = {project_name}', startAt=i, maxResults=chunk_size, fields=fields)
        i += chunk_size
        issues += chunk.iterable
        if i >= chunk.total:
            break
    return issues
issues = get_all_issues(jira, 'PROJECTNAME', ["id", "fixVersion"])

 

#3

from jira import JIRA

jira = JIRA(server='https://URL.atlassian.net', basic_auth=('USER', 'PASS))

issue = jira.issue('PROJECTNAME-xxx')
print(issue.fields.summary)

 

#4

from atlassian import Jira

jira = Jira(

    url='https://URL.atlassian.net',

    username='USER',

    password='PASS',

    cloud=True)

JQL = 'project = PROJECTNAME ORDER BY updated DESC'

data = jira.jql(JQL)
print(data)

 

In all of these i got the error (or similar):

{"errorMessages":["The value 'PROJECTNAME' does not exist for the field 'project'."],"warningMessages":[]}

 

What is missing from my code to connect to the API and get all issues on my project? (about 4k issues there that i'm trying to analyse)

 

1 answer

0 votes
Mohamed Benziane
Community Champion
October 8, 2023

Make sure that you're using basic auth in your first script. Then make sur that you have the correct permission in the project.

Thiago Portocarrero de Lima
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!
October 9, 2023

By basic auth you mean use 
header = {username='USER', password='PASS'}??

 

And by correct permission you mean admin? I am

Mohamed Benziane
Community Champion
October 9, 2023

https://requests.readthedocs.io/en/latest/user/authentication/

with requests you can use this

requests.get('https://httpbin.org/basic-auth/user/pass', auth=('yourMailAddress', 'Token'))

You need to have access to the project to be able to get the data by API. Do you have access to the issue in the UI ?

Suggest an answer

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

Atlassian Community Events