Coder Social home page Coder Social logo

Comments (12)

arvindkrishnakumar-okta avatar arvindkrishnakumar-okta commented on July 22, 2024

@DREW1990 Thanks for your question! Our Python SDK team will follow-up on this after the holidays.

from okta-sdk-python.

serhiibuniak-okta avatar serhiibuniak-okta commented on July 22, 2024

@DREW1990 Could you please, provide more details? (i.e. some code, sample output, etc.)
Full example under this section https://github.com/okta/okta-sdk-python#get-and-set-custom-attributes shows how to get custom attribute. It should be accessible via {user_obj}.profile.{custom_attribute_name}.

from okta-sdk-python.

DREW1990 avatar DREW1990 commented on July 22, 2024

Here's an example using requests to get an existing custom attribute (badgeNumber) from a user:

def get_badge_number(user):
    url = f'{okta_url}/api/v1/users/{user}'
    headers = {
        "Accept": "application/json",
        "Content-Type": "application/json",
        "Authorization": f"SSWS {okta_token}",
    }

    response = requests.get(url, headers=headers)
    print(response.json()['profile']['badgeNumber'])

Which returns a string of numbers.

However, when using the Okta SDK, I'm unable to retrieve the value for badgeNumber:

async def get_badge_number(user):
    user_info, response, error = await client.get_user(user)
    print(user_info.profile.badgeNumber)

This results into an error: AttributeError: 'UserProfile' object has no attribute 'badgeNumber'

The example in the README shows how to assign and create a custom attributes. However, I couldn't find a way to get any existing custom attributes. Maybe I just need more guidance on how to pull the information with the SDK?

from okta-sdk-python.

serhiibuniak-okta avatar serhiibuniak-okta commented on July 22, 2024

@DREW1990 Thank you for detailed response.
Currently, for variables set via config we use lowerCamelCase, but for object attributes (i.e. pythonic-way) snake_case.
Could you please, try access that value in the following way:

user_info.profile.badge_number

?
I believe, that's the way how it worked previously with regular attributes, i.e. described in model, like firstName and first_name.

from okta-sdk-python.

DREW1990 avatar DREW1990 commented on July 22, 2024

Thanks for the quick response! Unfortunately that didn't work either:

async def okta_employee(user):
    user_info, response, error = await client.get_user(user)
    print(user_info.profile.badge_number)

AttributeError: 'UserProfile' object has no attribute 'badge_number'

from okta-sdk-python.

serhiibuniak-okta avatar serhiibuniak-okta commented on July 22, 2024

Hmm, could you please, show the output of print(user_info.profile)? Maybe, some clue is inside

from okta-sdk-python.

DREW1990 avatar DREW1990 commented on July 22, 2024

For privacy reasons I can't show the full output. But I did extract all of the keys.

Here are the list of profile keys that get returned when using the SDK:

city
cost_center
country_code
department
display_name
division
email
employee_number
first_name
honorific_prefix
honorific_suffix
last_name
locale
login
manager
manager_id
middle_name
mobile_phone
nick_name
organization
postal_address
preferred_language
primary_phone
profile_url
second_email
state
street_address
timezone
title
user_type
zip_code

When using the Okta API directly with requests, it will only show the attributes that are not None. I get the following keys:

lastName
city
displayName
badgeNumber
subDepartment
title
login
employeeNumber
division
officeLocation
mobilePhoneCountryCode
company
state
department
email
hireDate
manager
costCenter
secondEmail
managerId
team
firstName
employeeType
mobilePhone
userType

Here are the custom attributes that we set in Okta:
Screen Shot 2020-12-30 at 10 45 50 AM

from okta-sdk-python.

serhiibuniak-okta avatar serhiibuniak-okta commented on July 22, 2024

Thank you for all the details. Very interesting, looks like a bug. Let me investigate it. Are you unblocked using requests?

from okta-sdk-python.

DREW1990 avatar DREW1990 commented on July 22, 2024

Awesome, thanks for the help! And nope, I can use requests for now. My team is just looking forward to using the Okta SDK for our projects going forward so we have some sort of consistency in our projects.

from okta-sdk-python.

serhiibuniak-okta avatar serhiibuniak-okta commented on July 22, 2024

Glad to hear that! But we will be able to release new version with fix only after all holidays. Feel free to add anything to this issue you find might be useful.

from okta-sdk-python.

serhiibuniak-okta avatar serhiibuniak-okta commented on July 22, 2024

@DREW1990 I can't reproduce the error.
I've added attribute and it works for me:
Screenshot 2021-01-08 at 14 16 59

Could you please try run the following script with your config?

from okta.client import Client as OktaClient
import asyncio

async def main():
    client = OktaClient()
    users, resp, err = await client.list_users()
    for user in users:
        try:
            print(f'{user.profile.first_name} has Badge Number: {user.profile.badge_number}')
        except:
            print(f'{user.profile.first_name} has no Badge Number.')

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

my output:

John has Badge Number: 123
Serhii has no Badge Number.

from okta-sdk-python.

serhiibuniak-okta avatar serhiibuniak-okta commented on July 22, 2024

@DREW1990 I am going to close this issue as resolved, because it looks like staled and I can't reproduce the issue: it works for me with client.get_user, client.list_users, etc. But please reach out to us if you find that your issue still exists.

from okta-sdk-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.