Using python-redmine module, is there a way to list all users assigned to a project through the Redmine API?
I've found that I'm able to request information about individual users, and that may API Key user is only assigned to a specific project and it can only see other users on the project. So I can do the following but it is hugely inefficient:
from redmine import Redmine
redmine = Redmine("https://myserver.net/", key="blahblah")
my_users = []
for x in range(1, 301):
try:
user = redmine.user.get(str(x))
my_users.append(user.id)
except:
print "",
The above code gets me what I want, a list of the users on a project... but takes way too long to be practical. Plus there may be user IDs higher than any range I pick.
Update: Here is what I got to work, thnx @njzk2
my_users = []
project = redmine.project.get('myproject')
for membership in project.memberships:
my_users.append(membership.user.id)
The answer by njzk2 is good but it still makes 2 separate API calls:
redmine.project.get('my_project')
redmine.project.get('my_project').memberships
So if you need to get all available details of the project first and all the members of the project second, then it's the best available option. But if you only need to get the members, you can do it in one API call via:
redmine.project_membership.filter(project_id='my_project')
(docs)
You're probably wondering why there are so many ways to do one thing, well, because there can be different use cases and python-redmine tries it's best to provide different ways to achieve things. So you'll have to look through documentation thoroughly and find the best available way that works for your exact case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With