Get Users List Using Python Expecting Json and not UserEntityListing

Hi

I am using https://developer.genesys.cloud/api/rest/v2/users/#get-api-v2-users to retrieve a list of users which I would like to use the json.loads() function to traverse the entities object, however, when I use the
/api/v2/users endpoint I am expecting a json response but I see that I am getting a type of UserEntityListing

What is the UserEntityListing?
How do I get the json?

Thank you.

Hello,

If you are using the python SDK I think the to_json() function can solve this issue.

UserEntityListing is a built-in data model. More about UserEntityListing here: https://developer.genesys.cloud/api/rest/client-libraries/python/UserEntityListing#userentitylisting

Hope this helps!

best

1 Like

Hi Chris,

I'm going to jump in here and provide a little more detail. By default, we generate our entire Python SDK off of our swagger documentation and thus we generate Python classes for both the input and output objects. By default, that means our API will return a Class object and not the raw JSON or an out of the box Python dictionary. Here is a nice article that talks about JSON serialization in Python. You can not use the Python dumps() method out of the box to return a map representation of the response body.

You have two options:

  1. If you truly just want the raw JSON string you can use the to_json function laid out by Ebenezer. You can then use the a dumps() method to convert that JSON string into a dictionary.

  2. If you are just trying to get a python dictionary containing your JSON, you can use the api_cients.sanitize_for_serialization() method. This is the same method we use in the SDK to take a pass in class and convert it to a Python map. Even if you don't want to use the method, you can take a look at the source code from the link to see it in action.

Thanks,
John Carnell
Manager, Developer Engagement

1 Like

Hi Ebenezer,

Thank you very much, this has worked.

Kind Regards,
Chris Carr

Hi John,

Thank you for this detail and information. This is really helpful to me.

Thank you.

Kind Regards,
Chris Carr

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.