<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
0D54z00007UfGkDCAVOkta Classic EngineAdministrationAnswered2024-03-25T07:24:05.000Z2022-03-05T11:29:52.000Z2022-03-08T09:40:47.000Z

AviS.97166 (Customer) asked a question.

Connecting to Okta APIS by using Python

Can we connect to okta APIS by using Python??

I am getting error when trying to connect to Get Users API with the below code:

 

import requests

import json

api_token = ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’

headers = {‘Content-Type’: ‘application/json’,‘Accept’:‘application/json’,

‘Authorization’:‘SSWS {api_token)’}

result = requests.get(‘https://{domain}.oktapreview.com/api/v1/users’)

 

Please help me with the code if you know how to connect to Okta APIS by using Python???

 

 


  • bz6fg (bz6fg)

    Hi,

     

    Have you tried to add the headers in the request? e.g:

     

    result = request.get('‘https://{domain}.oktapreview.com/api/v1/users’, headers=headers)

     

    Also in the headers it says Authorization’:‘SSWS {api_token)' (you are starting with a "{" and ending with a ")". For testing, replace ")" with a "}" or hardcode the token inside the string.

     

    e.g: 'Authorization': 'SSWS XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

     

    I hope it helps, let me know if you need additional assistance!

     

    /Alexander

    Expand Post
    • AviS.97166 (Customer)

      Hii Alexander Ling

      I have tried hardconding the API Token and sending request with headers.

      Still the error is:

      HTTPSConnectionPool(host='oktadomiain.okta.com', port=443): Max retries exceeded with url: /api/v1/users (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f8dc27bd070>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

       

      Please help me resolving it if you can.

       

      Thanks for your time and help.

      Expand Post
  • bz6fg (bz6fg)

    Hi,

     

    what url are you using? Seems like oktadomiain.okta.com is not correct. What is your domain called? Because the error is telling you that it cannot find the specified endpoint.

    • AviS.97166 (Customer)

      Hi Alexander

      I have replaced it here but i am using the correct url of my developer tenant.

    • AviS.97166 (Customer)

      Yes with the headers declared and defined above it.

  • bz6fg (bz6fg)

    Hi,

     

    I am not sure what you are doing, this works without any problems for me. Just replace ADD_TOKEN_HERE with your token. Do not add or remove any other characters like ' " ) ( just add the token inside the string.

     

    import requests

    import json

     

    headers = {

        "Content-Type": "application/json",

        "Accept":"application/json",

        "Authorization":"SSWS ADD_TOKEN_HERE"

    }

     

    result = requests.get("https://dev-number.okta.com/api/v1/users", headers=headers)

    print(result)

    Expand Post
  • AviS.97166 (Customer)

    Hi Alexander Ling

    I was able to trace the issue and solve it. The code was absolutely fine but as I was running it from Online Compiler it gave a connection error as I called the API from Frontend. When called after installing python on local machine works absolutely fine,

     

This question is closed.
Loading
Connecting to Okta APIS by using Python