-->

Welcome to our Coding with python Page!!! hier you find various code with PHP, Python, AI, Cyber, etc ... Electricity, Energy, Nuclear Power

Showing posts with label Jira API. Show all posts
Showing posts with label Jira API. Show all posts

Tuesday, 2 May 2023

Step by Step how to access the hosted Jira API via python

Here are the step-by-step instructions for accessing the hosted Jira API via Python:

  1. Install the required Python libraries:

    • requests
    • jira

    You can install them using pip:

    pip install requests jira
  2. Log in to your Jira account and navigate to the API tokens page (Settings > Security > API tokens). Generate a new API token and copy it.

  3. Create a new Python script and import the required libraries:

    python
    import requests from jira import JIRA
  4. Create an instance of the JIRA class and pass the Jira URL and API token to it:

    python
    options = { 'server': 'https://your-jira-instance.atlassian.net' } api_token = 'your-api-token' jira = JIRA(options, basic_auth=('email@example.com', api_token))

    Replace your-jira-instance with the name of your Jira instance and email@example.com with your Jira login email.

  5. Test the connection by retrieving a list of issues from Jira:

    python
    issues = jira.search_issues('assignee=currentuser()') for issue in issues: print(issue.key)

    This will print the keys of all issues assigned to the current user.

  6. You can now use the Jira API to perform various operations, such as creating, updating, and deleting issues. Refer to the JIRA library documentation for more details on how to use the API.

That's it! You can now access the hosted Jira API via Python.

Wednesday, 17 July 2019

JIRA 5.0, REST API, jira-python, Start/End Date

  1. How to create issues with jira-python or REST API so I could set the Create/Resolve/Close date correctly?
  2. How to set status of the issue created from the above?

Saw this awesome REST API library/wrapper, jira-python, at Atlassian Summit 2012. It seems to give me what i need to perform a heavy migration work of mine.
I think the external project import does not allow multiline description imports, so i have chosen to try using jira-python for my migration work.
How to create issues with jira-python or REST API so I could set the Create/Resolve/Close date correctly?

You have to set the create date in issue creation -- JIRA does that for you. Also, it automatically handles date updating when you transition issues, so you don't have to worry about that either. Take the date fields out of your fields dict and you should be fine.

How to set status of the issue created from the above?

When you create an issue, JIRA will use the issue type's associated workflow to determine what its status is. Once an issue is created, you can transition it to different statuses using the transitions() and transition_issue() methods.

In your case, it sounds like you want to preserve the original times and dates that issues were created. If so, then using the REST API isn't what you want; it uses the same access rules any real user has when they interact with the web application. You'll probably want to do a backup/restore if you want to preserve all the original information -- see http://aclabink.com/21047061/how-to-set-status for details on that.

Sunday, 23 June 2019

What server to use to connect python with jira api

I have ran across this when I have special characters in my password and it doesn't get parsed well in the script.
Try
from jira import JIRA
import getpass

password = getpass.getpass()

options = {'server': 'url'}
jira = JIRA(options, basic_auth=('username', password))


If somebody still need a solution, you can install JIRA rest api lib https://pypi.python.org/pypi/jira/. Just a simple example :
from jira.client import JIRA

jira_server = "http://yourjiraserver.com"
jira_user = "login"
jira_password = "pass"

jira_server = {'server': jira_server}
jira = JIRA(options=jira_server, basic_auth=(jira_user, jira_password))

group = jira.group_members("jira-users")
for users in group:
    print users


import urllib2, base64
import requests
import ssl
import json
import os
from pprint import pprint
import getpass

UserName = raw_input("Ener UserName: ")
pswd = getpass.getpass('Password:')

# Total number of users or licenses used in JIRA. REST api of jira can take values of 50 incremental
ListStartAt = [0,50,100,150,200,250,300]
counter = 0
for i in ListStartAt:
    request = urllib2.Request("https://jiraserver.com/rest/api/2/group/member?groupname=GROUPNAME&startAt=%s" %i)

    base64string = base64.encodestring('%s:%s' % (UserName, pswd)).replace('\n', '')
    request.add_header("Authorization", "Basic %s" % base64string) 
    gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
    result = urllib2.urlopen(request, context=gcontext)

    JsonGroupdata = result.read()
    jsonToPython = json.loads(JsonGroupdata)

    try:
        for i in range (0,50):
            print jsonToPython["values"][i]["key"]
            counter = counter+1
    except Exception as e:
        pass
print counter

Rank

seo