I'm using Gitea and I try to create a user using an API call in PowerShell:
Testing Plateforme : https://try.gitea.io/
API URL : https://try.gitea.io/api/swagger
API Token : 3bb81a498393f4af3d278164b5755fc23b74b785
Username : Will-stackoverflow
Password : willwill
Here it's what I have tried so far :
# Filling my var with some data
$username="myuser"
$email="[email protected]"
$full_name="My User"
$password="P@$$w0rd"
# Building a hash with my data
$hash = @{
Email = $($email);
full_name = $($full_name);
login_name = $($username);
Password = $($password);
send_notify = "false";
source_id = 0;
Username = $($username)
}
# Converting my hash to json format
$JSON = $hash | convertto-json
# Displaying my JSON var
$JSON
Invoke-WebRequest -uri "http://try.gitea.io/api/v1/admin/users?access_token=3bb81a498393f4af3d278164b5755fc23b74b785" -Method POST -Body $JSON
My $JSON
var is fed properly :
{
"Password": "P@w0rd",
"full_name": "My User",
"Username": "myuser",
"Email": "[email protected]",
"source_id": 0,
"login_name": "myuser",
"send_notify": "false"
}
But there is the result (from my prod environement as I can't get it to work at all using the online plateforme) :
To me it sounds like the fields "Username"
, "Email"
and "Password"
are required, but they are filled in my displayed JSON. What am I missing or doing wrong ?
EDIT :
Adding the -ContentType 'application/json'
parameter to the Invoke-WebRequest
command as suggested by Theo :
Invoke-WebRequest -H 'Authorization: token AUTH_TOKEN_HERE
? – Bender the Greatest"send_notify": "false"
into"send_notify": $false
. That way it receives a Boolean value instead of the string"false"
. I have edited my answer. – Theo