1

I use self hosted Jira and I'm currently trying to connect to the Jira api using a python script (and the requests library) having 2fa enabled by my organization. I'm not an admin of the project and after creating a personal access token and using it as a Bearer token I only got so far to get a response from the server telling me to put in the OTP to proceed. I was thinking whether I could possibly pass the OTP as part of the authorization header when making the request to the api but couldn't find any useful hints on how to do that. I have also been looking into OAuth tokens but from my understanding I'm unable to create one since I don't have the option to create an application link within Jira (since I'm not an admin). Does anyone have an idea on how I could manage to establish the connection to the api?

Any help would be appreciated!!

Cheers,

Liz

Hemanth Kumar
  • 2,728
  • 1
  • 4
  • 19
Liz
  • 11
  • 3

1 Answers1

0

Hey @Liz try this project for inspiration - https://github.com/dren79/JiraScripting_public

I built it out on the below examples from the API documentation.

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

url = "https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}"

auth = HTTPBasicAuth("email@example.com", "<api_token>")

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

response = requests.request(
   "GET",
   url,
   headers=headers,
   auth=auth
)

print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
Dren79
  • 89
  • 6