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

Still need help?

The Atlassian Community is here for you.

Ask the community


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.

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)





Last modified on Feb 23, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.