Get "403 Forbidden" when creating a new user through the API

I am using the API to attempt to create a new user. I am using GitLab SaaS, and am an administrator.

I’ve tried both a Group Access Token and Personal Access Token with full API permissions on each, but when I try to create a user I receive “403 Forbidden”.

Below is an example of the cUrl request I am using:

curl --location --request POST 'https://gitlab.com/api/v4/users' \
--header 'Private-Token: redacted \
--header 'Content-Type: application/json' \
--data-raw '{
	"email": "jdoe@email.com",
	"name": "John Doe",
	"reset_password": "True",
	"username": "jdoe"
}'

I’ve tried searching the forums and have seen other “403 Forbidden” related questions, but none of those were related to creating a user, and many were resolved years ago.

Hi @devenv :wave: :slightly_smiling_face:

Two things come to mind:

  • this might be a silly one, but did you try to use PRIVATE-TOKEN (all uppercase)?
  • this might be a better one, you need to make sure to use a Personal Access Token of an administrator user. I’m not sure, but you might also to grant sudo privileges other that the api to that token :thinking:

Hi @devenv

You can’t create new user via API on GitLab SaaS.

I didn’t notice that, thanks for correcting me @balonik :handshake: :slightly_smiling_face: