How to add a user/roles to DNG programmatically through API? Using Python requests
I've been running into issues as to how to add users through the API. I've been looking at this website: https://jazz.net/wiki/bin/view/Main/DraftTeamProcessRestApi#Members_collection and specifically the section "Members collection: POST". I've copied the data in the request body example and edited it to fit my services. I then added it to an xml file and as a string. I've tried posting both of them but I keep getting a 400 "If the request body is invalid" error. Could anyone point me in the right direction for this?
s = requests.Session()
eaders3 = {
I've tried changing data to data = xml as well. xml is a String """ with the edited request body example.
|
One answer
Ian Barnard (2.1k●6●13)
| answered Jun 16 '22, 3:52 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER The user must already exist. No AFAIK you can't create a user using this API - for Liberty user registry you can use repotools-jts -importUsers , see https://www.ibm.com/docs/en/elm/7.0.2?topic=reference-importusers or for LDAP the users must exist in LDAP and then I guess (haven't tried it) =importUsers can assign licenses. |
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.
Comments
What version+ifix are you using?
Also, you should be using header:
Yes I'm trying to add users and roles to an already created project.
I've managed to log in manually as well as through code.
The exact error I'm getting is "Request could not be parsed as XML."
The url is "https://website.name.com/rm/process/project-areas/_S-01wKEAEeujI9hRpLoqWg/members"
I changed the Content type to what you said. I previously had it but I kept getting a 404 error. Now that I changed the print statement to output the error code though it's saying "User 'testuser1' was not found". So at this point it seems like I need to create a test user and then add them to the project I think. Do you know if the DNG API is able to create users or only add them to project?
Yes, it is absolutely necessary that the user already exists in the server. You can use repotools commands e.g. -importUsers or -createUser or synchronize with LDAP. I am a ware of Java API that can be used, there is likely some WEB API to manage users, but I have not looked at that. The rest API explained in https://jazz.net/wiki/bin/view/Main/DraftTeamProcessRestApi seems to be only to manage on a project area level. You would have to make sure the users exist, before you add them.