pythonpython-3.xgetokta-api

How to Run this API Request Using Python


I am very new to python and API Integration. Can anyone pls tell me how do I run this okta document using python?

curl -v -X GET
-H "Accept: application/json"
-H "Content-Type: application/json"
-H "Authorization: SSWS ${api_token}"
"https://${yourOktaDomain}/api/v1/apps"


Solution

  • You can use urllib for do it.
    Example:

    from urllib.request import Request, urlopen
    
    api_token = "..."
    yourOktaDomain = "..."
    
    headers = {
        "Accept": "application/json",
        "Content-Type": "application/json",
        "Autorization": "SSWS " + api_token
    }
    
    request = Request("https://" + yourOktaDomain + "/api/v1/apps", headers=headers)
    response = urlopen(request)
    data = response.read()