How to login to OKTA and access an app using python for automation purpose

Hello All, As part of my organization I’m planning to get a list of Jira tickets and update the ticket in Jira. For this, I need to authenticate to OKTA and then access the Jira app. I’m trying to automate this scenario and I’m able to login with basic auth but every request that I try for getting the apps from okta is giving me 401 error. Can someone guide me on how to automate this kind of scenario/ whats wrong with the below code? Any help would be appreciated. Thanks.

import requests
url = “https://logon.okta.com/api/v1/authn
payload = “”"{
“password”: “PASSWORD”,
“username”: “USERNAME@emal.com”,
“options”: {
“warnBeforePasswordExpired”: true,
“multiOptionalFactorEnroll”: false
}
}"""
headers = {
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/json’
}
response = requests.request(“POST”, url, headers=headers, data = payload)
print(response.json())

get the session token for accessing the okta apps

okta_token = response.json()[“sessionToken”]
headers= {
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/json’,
‘Authorization’: 'SSWS '+okta_token
}

wanted to login to okta and then login to jira and access a ticket something like below

jira_url = “https://jira.official.org/rest/api/2/issue/GPS-14432

apps_list_url = “https://logon.okta.com/api/v1/apps
response = requests.request(“GET”, apps_list_url, headers=headers)
print(response.status_code)

where SSWS token is, you need to provide not a session token, but API token which is generated by Okta Admins in Security -> API -> Tokens