How to access the JIRA API via bearer token using Python code?


JIRA is a project management tool that helps teams track bugs, releases, plan projects, etc.
There are times when the team needs to access the release and bug data to create custom dashboards to show the trends, like bug trends and releases in a year. There come the JIRA APIs, which come in handy to pull data from the backend server and use it for your custom needs.

You can learn about JIRA APIs from its official site:  https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#about


JIRA server can be setup on-premise or you can use the cloud version of JIRA (SAAS).

What is a bearer token?

Bearer tokens enable requests to authenticate using an access key, such as a JSON Web Token (JWT). The token is a text string, included in the request header.

Here, we can see how we can use a bearer token to authenticate the JIRA server using Python code.


#!/usr/bin/python3.6

# library modules
import requests

jira_server_url = "https://xx.yy.zz/"

bearer_token = "_place_your_bearer_token_which_is_in_string_format_"

headers = {"Authorization": f"Bearer {bearer_token}"}

response = requests.get(jira_server_url, headers=headers)

print(response)

 


In the response, you will receive response code 200. This means you are successfully authenticated to JIRA sever. From here on, you can build the query or get the data from hitting the right endpoints.

For example, if you want to get the data of releases in a particular workspace/project, you can use the below endpoint.

JIRA api:

https://xx.yy.zz/rest/api/latest/project/<replace_with_project_id>/versions/

 

Hope this helps. Let me know if you get this working using this simple piece of code.

PS: I am too learning.

 

Thanks for your time.