Panda
Panda

Reputation: 643

Jira api to search all issues in Jira using python

I want to list/search all the issues in Jira. I have a code like :

url = 'https://company.com/rest/api/2/search'


auth = HTTPBasicAuth("username", "password") // I tries token as well

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

query = {
    'jql': 'project=PRKJECTKEY',
    'startAt': 0
}
response = requests.request(
    "GET",
    url,
    headers=headers,
    auth=auth,
    params=query
) 

I am not sure if the password should be token or the actual password and the url should be should be starting from companyname.com. This gives me <Response [401]> but i have all the permissions with the account.

Can someone help me with the authentication is supposed to be used this way.

Upvotes: 2

Views: 4210

Answers (2)

Andreas G.
Andreas G.

Reputation: 300

I can only describe my way of accessing the JIRA-API:

1. I am using an API-key for this which one can easily create online, if one has the necessary permissions

(https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/)

2. You need to set up the Jira-object to query issues first
user = '[email protected]'

apikey = 'xxxxxxxxxxxxxxxxx'
server = 'https://companypage.atlassian.net'

options = {
 'server': server
}

jira = JIRA(options, basic_auth=(user, apikey))
3. Now, you can use the Jira-object to query with
tickets = jira.search_issues('text ~ "my search text" ORDER BY updated DESC')

Now, you can look what you got back and play with the results

for ticket in tickets:
  print(ticket)

For Packages, you only need to import JIRA at the top (obviously, need to install jira first):

from jira import JIRA

Upvotes: 2

JohnyCapo
JohnyCapo

Reputation: 302

Well, why don't you use atlassian-python-api?

https://community.atlassian.com/t5/Jira-articles/Atlassian-Python-API-s/ba-p/2091355

It's much easier to work with Jira via their own library. I have been working with Confluence via this and it's pretty simple. Take a look it may solve your problem.

EDIT: here is documentation. https://atlassian-python-api.readthedocs.io/

Upvotes: 1

Related Questions