get_users not working - python library

Hi!, im a developer and i want to integrate you API, I was readed all the documentation in asana developers but i cant do work correctly. My app its using python 3.8 and when i try to get users doesn’t works
In the documentation you mention the get_users() doesn’t needs params but when i try to execute the code i have this error.
asana.error.InvalidRequestError: Invalid Request: Need to specify a workspace yo paginate!

When i put the gid of the workspace in the params of the function i have the next error.
ValueError: dictionary update sequence element #0 has length 1; 2 is required
this is my code:

token = ‘my token’
client = asana.Client.access_token(token)

a = client.users.get_users(‘MY WORSPACE’)

b = list(a)

print(b)

return

I await you response. Thanks!

Hi @martin_sanchez and welcome to the forum,

FYI I changed the title of your post to be more informative about your issue.

get_users definitely needs a workspace as what it’s doing is “get all of the users in a workspace”, so adding the workspace gid was the right thing to do.

Which line of code is this error occurring on? I’m not a python developer but from what I can see online, you’re probably not handling the return value from the Asana call properly. My guess would be the error is occurring on b = list(a) but you’ll have to check that.

1 Like

Change this line
a = client.users.get_users(‘MY WORSPACE’)

to

a = client.users.get_users({ ‘workspace’: ‘MY WORSPACE’})

should be fine

Here is the function in my existing code for your reference

def get_users_sub(self, **kwargs):

    para = {

      'workspace': self.workspace_gid

    }

    result = self.client.users.get_users(para, opt_pretty=True)

    res = list(result)

    # ez_log_json(res)

    return res
1 Like