Add a user to multiple groups via a Multicode
Task
Assign a user to one or many groups via a Multicode.
Note: A multicode
can join a user with one just one group or many groups depending on how many groups are associated with that multicode
.
Multicode Diagram
Find the Endpoint
Go to the API Reference section of this documentation and to the controller called Public Membership.
There you will find an endpoint called ‘/api/membership/join/{username}/to/{multicode}’
If you click on the endpoint it will display more information.
This assigns a user to a multicode
which references a collection of one or many groups and the user is assigned to all of the groups that the multicode
references.
Code
Here is example code in Python (3.6.8) of how to assign a user to one or many groups via a Multicode
.
Note: This doesn’t include getting an Access Token to be able to communicate with the Bracken API. Please add the necessary code to get an Access Token.
# Declare your username
username = YOUR_USERNAME
# Declare your multicode
multicode = YOUR_MULTICODE
# using the endpoint to assign a user to one or many groups via a Multicode
urlAssignUserToAGroupViaMulticode = 'https://api.brackenlearning.com/api/membership/join/{username}/to/{multicode}'
response = s.get(urlAssignUserToAGroupViaMulticode)
print(response)
print(response.json())
The part to focus on for this tutorial is this line.
# using the endpoint to assign a user to one or many groups via a Multicode
urlAssignUserToAGroupViaMulticode = 'https://api.brackenlearning.com/api/membership/join/{username}/to/{multicode}'
Which is where we use the endpoint that we found in the API Reference document to assign a user to one or many groups via the multicode
.
Important to note
The parameters that we are declaring for the API call determine which user we are assigning to one or more groups.
The username
that is used in the URL of the get
call is unique within that domain and will only refer to one user. While the multicode
can reference one or many groups and this means that the user will be assigned to all of the groups that the multicode
references.
Response
The [200] response for this call will look like the example below. Please note the access
will default 0 for the Group Based Permissions.
{
"user": {
"userkey": 0,
"username": "Test-User",
"firstname": "Test",
"lastname": "User",
"email": "testuser@thetarngroup.com",
"verifiedemail": "testuser@thetarngroup.com",
"password": "HxTqaR3L72Zha1!iOlapKJ",
"parentkey": 0,
"friendlyname": "Test User",
"iconkey": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"storage": 0,
"mobile": "0000000000",
"domainkey": YOUR_DOMAIN_KEY,
"lastlogin": "2020-11-24T22:54:30.998Z",
"internaluser": false,
"masteraccess": false,
"groupaccess": false,
"designaccess": false,
"siteaccess": false,
"authoraccess": false,
"markeraccess": false
},
"membership": [
{
"memberkey": 0,
"zonekey": 0,
"userkey": 0,
"username": "string",
"expires": "2020-11-24T23:10:53.832Z",
"created": "2020-11-24T23:10:53.832Z",
"modified": "2020-11-24T23:10:53.832Z",
"access": "string",
"storage": 0,
"alertflags": 0
}
],
"groups": [
{
"groupkey": 0,
"title": "string",
"userkey": 0,
"username": "string",
"firstname": "string",
"lastname": "string",
"created": "2020-11-24T23:10:53.832Z",
"access": 0,
"role": "string"
}
]
}