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 = {
'Accept': 'application/rdf+xml',
'OSLC-core-version': '2.0',
'Content-Type': 'application/x-www-form-urlencoded',
#'Content-Type': 'application/xml;charset=UTF-8',
}
with open('pa-members-to-add.xml', 'rb') as f:
data = f.read().replace(b'\n', b'')
print(s.post(url3, headers=headers3, data=data))
One answer
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.
Comments
Ian Barnard
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Jun 16 '22, 12:00 p.m.What version+ifix are you using?
Ian Barnard
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Jun 16 '22, 12:08 p.m.Also, you should be using header:
Jacob Harland
Jun 16 '22, 12:27 p.m.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?
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Jun 20 '22, 2:27 a.m.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.