Can't create user using the API #2093

Closed
opened 2025-11-02 04:23:58 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @William-LP on GitHub (Jul 24, 2018).

  • Git version: 1.4.3
  • Operating system: Windows Server 2012 R2 Standard
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No (404 Not Found when calling the API)
    • Not relevant

Description

I try to create a user using PowerShell (Invoke-WebRequest command) calling the API :

$username="myuser"
$email="myuser@mydomain.com"
$full_name="My User"
$password="P@ssW0rd"

$hash = @{
     email = $($email);
     full_name = $($full_name);
     login_name = $($username);
     password = $($password);
     send_notify = "false";
     source_id = 0;
     username = $($username)
}

$JSON = $hash | convertto-json

$JSON

Invoke-WebRequest -uri "http://try.gitea.io/api/v1/admin/users?access_token=3bb81a498393f4af3d278164b5755fc23b74b785" -Method POST -ContentType 'application/json' -Body $JSON

Below what my $JSON looks like :

{
    "password":  "P@ssW0rd",
    "full_name":  "My User",
    "username":  "myuser",
    "email":  "myuser@mydomain.com",
    "source_id":  0,
    "login_name":  "myuser",
    "send_notify":  "false"
}

image

I am not 100% sure that's an issue (to me it looks like a Go error but I'm not a coder).
If I'm just mistaking the API call I'd be glad being explained how to get it to work, thank you 👍

Will

Originally created by @William-LP on GitHub (Jul 24, 2018). - Git version: 1.4.3 - Operating system: Windows Server 2012 R2 Standard - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [ ] MSSQL - [x] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [x] No (404 Not Found when calling the API) - [ ] Not relevant ## Description I try to create a user using PowerShell (Invoke-WebRequest command) calling the API : ``` $username="myuser" $email="myuser@mydomain.com" $full_name="My User" $password="P@ssW0rd" $hash = @{ email = $($email); full_name = $($full_name); login_name = $($username); password = $($password); send_notify = "false"; source_id = 0; username = $($username) } $JSON = $hash | convertto-json $JSON Invoke-WebRequest -uri "http://try.gitea.io/api/v1/admin/users?access_token=3bb81a498393f4af3d278164b5755fc23b74b785" -Method POST -ContentType 'application/json' -Body $JSON ``` Below what my `$JSON` looks like : ``` { "password": "P@ssW0rd", "full_name": "My User", "username": "myuser", "email": "myuser@mydomain.com", "source_id": 0, "login_name": "myuser", "send_notify": "false" } ``` ![image](https://user-images.githubusercontent.com/10053686/43150278-cd70a07a-8f69-11e8-8d6c-4005e8455304.png) I am not 100% sure that's an issue (to me it looks like a Go error but I'm not a coder). If I'm just mistaking the API call I'd be glad being explained how to get it to work, thank you 👍 Will
Author
Owner

@apricote commented on GitHub (Jul 24, 2018):

The field send_notify needs to contain a Boolean, you are currently sending "false" which is a String. Gitea can not parse your request into its internal format (CreateUserOption) and responds with this error instead.

To fix it just send "send_notify": false (without quotes).

@apricote commented on GitHub (Jul 24, 2018): The field `send_notify` needs to contain a `Boolean`, you are currently sending `"false"` which is a `String`. Gitea can not parse your request into its internal format (`CreateUserOption`) and responds with this error instead. To fix it just send `"send_notify": false` (without quotes).
Author
Owner

@William-LP commented on GitHub (Jul 24, 2018):

You hero 🥇

@William-LP commented on GitHub (Jul 24, 2018): You hero 🥇
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#2093