Hi Community,
The article here explained how to create a token in your Atlassian Account
To get started on APIs - Here's the Guide -> Link
In this article let us look at the Atlassian API using Python and the various approaches to using Python Modules to authenticate with Atlassian Account and interact with the APIs
One of the Modules I occasionally use is the atlassian-python-api module
https://atlassian-python-api.readthedocs.io
Install the atlassian-python-api module
pip install atlassian-python-api
Below is the sample code to authenticate to Atlassian Account where we mention the site, email as username, password, and cloud option as 'True'
from atlassian import Jira
jira = Jira(
url='https://your-site.atlassian.net',
username='email',
password='token',
cloud=True)
jql_request ='project = WSP AND issuetype = Story'
# '"epic link" = WSP-144'
issues = jira.jql(jql_request)
print(issues)
The methods we extract the data from Cloud are extensive and methods are flexible
Below is another example of the abstract way to get the data
# This code sample uses the 'requests' library:
# http://docs.python-requests.org
import requests
from requests.auth import HTTPBasicAuth
import json
import base64
url = "https://your-site.atlassian.net/rest/api/3/issue/WSP-70"
credentials = "Basic " + base64.b64encode("email:token".encode("ascii")).decode("ascii")
headers = {
"Accept": "application/json",
"Authorization": credentials
}
response = requests.request(
"GET",
url,
headers=headers
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
There are other modules as well one such popular is https://jira.readthedocs.io/installation.html
Do let us know how you are using Jira modules or Atlassian Python Modules to Interact with Atlassian Sites
Thanks,
Pramodh
Pramodh M
DevSecOps Consultant
DevTools
Bengaluru
663 accepted answers
5 comments