I have a socket mode Slackbot we use for support communications. I want it to be able to create Jira issues via the REST API - how do I authenticate. As users we use Azure based SSO to authenticate into Jira via a browser. How do I go about retrieving an auth token for REST API requests?
Here is a beginning:
#!/usr/bin/env python
#
#
# -----------------------------------------------------------------------------
"""
See https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-search/#api-rest-api-2-search-get
"""
# -----------------------------------------------------------------------------
import os
import json
import requests
from dotenv import load_dotenv
from requests.auth import HTTPBasicAuth
load_dotenv()
ORG = os.getenv("JIRA_ORG", None)
TOKEN = os.getenv("JIRA_API_TOKEN", None)
EMAIL = os.getenv("EMAIL", None)
if ORG == None:
raise("No organisation provided")
if TOKEN == None:
raise("No token provided")
if EMAIL == None:
raise("No email address provided")
ISSUE = "CNP-6001"
URL = f"https://{ORG}.atlassian.net/rest/api/2/search"
auth = HTTPBasicAuth(EMAIL, TOKEN)
HEADERS = {
"Accept": "application/json"
}
query = {
"jql": f"issue = {ISSUE}"
}
response = requests.request(
"GET",
URL,
headers=HEADERS,
params=query,
auth=auth
)
print(json.dumps(json.loads(response.text),
sort_keys=True,
indent=4,
separators=(",", ": "))
Add a .env file defining JIRA_ORG, JIRA_API_TOKEN and EMAIL
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.