Good morning all !
First of all, sorry for my level of English, it is low.
My goal is to be able to change (modify) the username of an existing account on my Gitlab self-managed but in command line to then automate it.
I looked at the Gitlab documentation and here are the links I checked:
with this documentation, here is what I concluded but unfortunately does not work and I can not understand how to change username with API:
The account is āmonicaā and i want to modify that by ājulieā
curl --request PUT --header "PRIVATE-TOKEN: ITISASECRET" "https://my.gitlab.server/api/v4/users?username=**monica**" --data "username=**julie**"
Here ! I hope you can help me !
The URL endpoint needs to specify the target userās ID. Use https://my.gitlab.server/api/v4/users
to find all usernames, then extract the ID (id
key in responses) of existing username monica
and send the PUT
request to https://my.gitlab.server/api/v4/users/ID
.
Also, what roleās credential are you using? To alter usernames, the personal authentication token needs to be from an admin role user, and the api
scope must be enabled when generating the token.
1 Like
Hello, first of all, thanks you ! it works !
For future people who would need to do the same :
the monica account is the Administrator account which is the only admin of the instance. I generated an āAccess tokenā with the api and sudo scopes.
after, I launched the following command:
curl --request GET --header "PRIVATE-TOKEN: ITSASECRET" "https://my.gitlab.server/api/v4/user"
the result:
{āidā:1,ānameā:āAdministratorā,āusernameā:āmonicaā,āstateā:āactiveā,āavatar_urlā:"https://seā¦
I get the ID which is 1. As soon as I run the following command, it doesnāt work, I have a 404 error.
curl --request PUT --header āPRIVATE-TOKEN: ITSASECRETā āhttps://my.gitlab.server/api/v4/users/1ā --data āusername=julieā
the result:
{āidā:1,ānameā:āAdministratorā,āusernameā:ājulieā,āstateā:āactiveā,āavatar_urlā:"https://seā¦
Thanks for the help . See you soon and merry christmas
1 Like