Managing Individual Users and Groups via REST
The fine-grained REST API described here may not be the best fit for your use case. See the following pages for alternatives:
- Active Directory Integration
- Managing Users and Groups via REST: Administer all entities at once.
Managing Users via REST
Before executing any of the actions below, you need to execute the following steps to get the authentication token:
Preparation: Login to get authentication token
export NEVISADMIN_URL=http://localhost:9080
export ADMIN_USER=admin
export ADMIN_PASSWORD=admin
# for https, you can add the -k flag to all curl commands to skip certificate verification
export AUTH_RESPONSE=$(curl -v -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -d "{\"userKey\":\"${ADMIN_USER}\",\"password\":\"${ADMIN_PASSWORD}\"}" "$NEVISADMIN_URL/nevisadmin/api/v1/login?tokenType=bearer")
export TOKEN=$(echo $AUTH_RESPONSE | sed -nE 's/.*"token" : "(.*)" }/\1/p')
Create User
Once the preparation explained above is done, execute the following steps to create additional user accounts within nevisAdmin 4:
export USER_KEY=john
export USER_PASSWORD=secret
export USER_EMAIL=[email protected]
export USER_GIVEN_NAME=John
export USER_FAMILY_NAME=Doe
export USER_DATA="{\"userKey\":\"${USER_KEY}\",\"password\":\"${USER_PASSWORD}\" ,\"email\":\"${USER_EMAIL}\" ,\"familyName\":\"${USER_FAMILY_NAME}\", \"givenName\":\"${USER_GIVEN_NAME}\"}"
curl --header "Content-Type: application/json" --header "Authorization: Bearer $TOKEN" --request POST --data "$USER_DATA" $NEVISADMIN_URL/nevisadmin/api/v1/users
Update User
Once the preparation explained above is done, execute the following steps to update user accounts within nevisAdmin 4:
export USER_KEY=john
export USER_EMAIL=[email protected]
export USER_GIVEN_NAME=John
export USER_FAMILY_NAME=Doe
export USER_DATA="{\"userKey\":\"${USER_KEY}\" ,\"email\":\"${USER_EMAIL}\" ,\"familyName\":\"${USER_FAMILY_NAME}\", \"givenName\":\"${USER_GIVEN_NAME}\"}"
curl --header "Content-Type: application/json" --header "Authorization: Bearer $TOKEN" --request PUT --data "$USER_DATA" $NEVISADMIN_URL/nevisadmin/api/v1/users/$USER_KEY
Update User Password
Once the preparation explained above is done, execute the following steps to update users passwords within nevisAdmin 4:
export NEW_PASSWORD=mysecretnewpassword
export USER_DATA="{ \"password\": \"$NEW_PASSWORD\" }"
curl --header "Content-Type: application/json" --header "Authorization: Bearer $TOKEN" --request PUT --data "$USER_DATA" $NEVISADMIN_URL/nevisadmin/api/v1/users/$USER_KEY/password
Delete User
Once the preparation explained above is done, execute the following steps to delete user accounts within nevisAdmin 4:
export USER_KEY=john
curl --header "Content-Type: application/json" --header "Authorization: Bearer $TOKEN" --request DELETE $NEVISADMIN_URL/nevisadmin/api/v1/users/$USER_KEY
Managing Groups via REST
Before executing any of the actions below, you need to execute the following steps to get the authentication token:
Preparation: Login to get authentication token
export NEVISADMIN_URL=http://localhost:9080
export ADMIN_USER=admin
export ADMIN_PASSWORD=admin
# for https, you can add the -k flag to all curl commands to skip certificate verification
export AUTH_RESPONSE=$(curl -v -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -d "{\"userKey\":\"${ADMIN_USER}\",\"password\":\"${ADMIN_PASSWORD}\"}" "$NEVISADMIN_URL/nevisadmin/api/v1/login?tokenType=bearer")
export TOKEN=$(echo $AUTH_RESPONSE | sed -nE 's/.*"token" : "(.*)" }/\1/p')
Create Group
Once the preparation explained above is done, execute the following steps to create additional groups within nevisAdmin 4:
export GROUP_KEY=admins
export GROUP_DESCRIPTION='Group of administrators'
export LDAP_DNS='[ "ou=Admins,o=Siven,c=ch" ]'
export GROUP_DATA="{\"groupKey\":\"${GROUP_KEY}\",\"description\":\"${GROUP_DESCRIPTION}\",\"ldapDNs\": ${LDAP_DNS} }"
curl --header "Content-Type: application/json" --header "Authorization: Bearer $TOKEN" --request POST --data "$GROUP_DATA" $NEVISADMIN_URL/nevisadmin/api/v1/groups
Update Group
Once the preparation explained above is done, execute the following steps to update groups within nevisAdmin 4:
export GROUP_KEY=admins
export GROUP_DESCRIPTION='Group of administrators updated'
export LDAP_DNS='[ "ou=Admins,o=Siven,c=ch" ]'
export GROUP_DATA="{\"groupKey\":\"${GROUP_KEY}\",\"description\":\"${GROUP_DESCRIPTION}\",\"ldapDNs\": ${LDAP_DNS} }"
curl --header "Content-Type: application/json" --header "Authorization: Bearer $TOKEN" --request PUT --data "$GROUP_DATA" $NEVISADMIN_URL/nevisadmin/api/v1/groups/$GROUP_KEY
Add User to Group
Once the preparation explained above is done, execute the following steps to add users to groups within nevisAdmin 4:
export GROUP_KEY=admins
export USER_KEY=john
export ADD_USER_DATA="{\"userKey\":\"${USER_KEY}\" }"
curl --header "Content-Type: application/json" --header "Authorization: Bearer $TOKEN" --request POST --data "$ADD_USER_DATA" $NEVISADMIN_URL/nevisadmin/api/v1/groups/$GROUP_KEY/users
Delete User From Group
Once the preparation explained above is done, execute the following steps to delete users from groups within nevisAdmin 4:
export GROUP_KEY=admins
export USER_KEY=john
curl --header "Content-Type: application/json" --header "Authorization: Bearer $TOKEN" --request DELETE $NEVISADMIN_URL/nevisadmin/api/v1/groups/$GROUP_KEY/users/$USER_KEY
Delete Group
Once the preparation explained above is done, execute the following steps to delete groups within nevisAdmin 4:
export GROUP_KEY=admins
curl --header "Content-Type: application/json" --header "Authorization: Bearer $TOKEN" --request DELETE $NEVISADMIN_URL/nevisadmin/api/v1/groups/$GROUP_KEY