How to pass a bearer token when making a Jira Align REST API call via Python

Platform Notice: Cloud and Data Center - This article applies equally to both cloud and data center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

This article demonstrates how to authenticate on Jira Align Rest API endpoint with the Bearer Token sending the calls from a Python Script.

The method 'POST' to create an EPIC is the example used here, but it does apply to any method and object supported by Jira Align.

  • A test with CURL/PostMan or Swagger can validate that the Token being used is valid, if the token does not work in any of these tests it will not work within the Python script as well.

  • An HTTP 401 Error, can indicate an Authentication issue (invalid token being used) or an Authorization issue (The user does not have access to the target object)

Solution

This solution is just for internal reference only. Jira Align Support team does not support third-party scripts, but it can be useful during troubleshooting or testing.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import requests url = "https://xxxx.jiraalign.com/rest/align/api/2/Epics" payload = " {"title":"testing epic creation via pythonscript", "state":1, "type":1,"description":"testing epic creation","primaryProgramId":xxx} " headers = { 'Accept': 'application/json;odata.metadata=minimal;odata.streaming=true', 'Content-Type': 'application/json;odata.metadata=none;odata.streaming=true', 'Authorization': 'Bearer user:XXXXXXXXXXXX', } response = requests.request("POST", url, headers=headers, data=payload) print(response.text)

Updated on April 14, 2025

Still need help?

The Atlassian Community is here for you.