Gitea Rest API to create a new admin user

I am using gitea latest image. It used Postgres DB (using the latest postgress image).

As part of automation, I need to create an admin account using Gitea rest API. I have tried the below API. But It is not working.

https:///user/sign_up

Please help me at the earliest as its a showstopper issue for my development.

This should do it.
https://try.gitea.io/api/swagger#/admin/adminCreateUser

https://try.gitea.io/api/swagger#/admin/adminCreateUser

Above will work once the git admin is user is created. Above wont work if there is no admin user.

My requirement is that I need to create a admin user once the Gitea is launched.

Plesae help how to creaate a new admin user in Gitea once its launched using API.

Rather than using the API, you could use the CLI https://docs.gitea.io/en-us/command-line/#admin

Also note: the first user that signs up for Gitea instance is the admin

@BagaSiva

package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "http://localhost:3000/user/sign_up"

	payload := strings.NewReader("user_name=blub&email=blub%40bla.bla&password=dsklfjaskjfKAKLJSAKDJ1827.&retype=dsklfjaskjfKAKLJSAKDJ1827.")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("cookie", "lang=en-US; i_like_gitea=8e2779a79e7d3e28; _csrf=uBwdvQ2EKSS69kVzPIGOPI1OmoU6MTU5NDMxMTk2NzA1ODIxMjgzNw")
	req.Header.Add("content-type", "application/x-www-form-urlencoded")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}

or a simple curl

curl --request POST \
  --url http://localhost:3000/user/sign_up \
  --header 'content-type: application/x-www-form-urlencoded' \
  --cookie 'lang=en-US; i_like_gitea=8e2779a79e7d3e28; _csrf=uBwdvQ2EKSS69kVzPIGOPI1OmoU6MTU5NDMxMTk2NzA1ODIxMjgzNw' \
  --data user_name=blub \
  --data email=blub@bla.bla \
  --data password=dsklfjaskjfKAKLJSAKDJ1827. \
  --data retype=dsklfjaskjfKAKLJSAKDJ1827.

and as @techknowlogick said, the first user is always the admin.

Hi buddyspencer,
I have tried above curl command. But am getting below HTML response and not created the git credentials.
As its a showstopper for my development, could you help me on the same.

I am using below curl command

curl --request POST --url <> --header ‘content-type: application/x-www-form-urlencoded’ --cookie ‘lang=en-US; i_like_gitea=8e2779a79e7d3e28; _csrf=uBwdvQ2EKSS69kVzPIGOPI1OmoU6MTU5NDMxMTk2NzA1ODIxMjgzNw’ --data user_name=gituser9 --data email=gituser9@git.com --data password=gituser9 --data retype=gituser9

Page Not Found - Gitea: Git with a cup of tea
    <script>
    /*
    @licstart  The following is the entire license notice for the
    JavaScript code in this page.

    Copyright (c) 2016 The Gitea Authors
    Copyright (c) 2015 The Gogs Authors

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
    ---
    Licensing information for additional javascript libraries can be found at:
      {{AppSubUrl}}/vendor/librejs.html

    @licend  The above is the entire license notice
    for the JavaScript code in this page.
    */
    </script>

    <link rel="shortcut icon" href="/img/favicon.png" />
    <link rel="mask-icon" href="/img/gitea-safari.svg" color="#609926">
    <link rel="preload" href="/vendor/assets/font-awesome/css/font-awesome.min.css" as="style" onload="this.rel='stylesheet'">
    <noscript><link rel="stylesheet" href="/vendor/assets/font-awesome/css/font-awesome.min.css"></noscript>
    <link rel="stylesheet" href="/vendor/assets/octicons/octicons.min.css">








    <link rel="stylesheet" href="/vendor/plugins/semantic/semantic.min.css">
    <link rel="stylesheet" href="/css/index.css?v=17b7ffb6cc1f3588d20dda49ffb651f0">
    <noscript>
            <style>
                    .dropdown:hover > .menu { display: block; }
                    .ui.secondary.menu .dropdown.item > .menu { margin-top: 0; }
            </style>
    </noscript>





    <style class="list-search-style"></style>

    <script src="/vendor/plugins/cssrelpreload/loadCSS.min.js"></script>
    <script src="/vendor/plugins/cssrelpreload/cssrelpreload.min.js"></script>

    <meta property="og:title" content="Gitea: Git with a cup of tea">
    <meta property="og:type" content="website" />
    <meta property="og:image" content="/img/gitea-lg.png" />
    <meta property="og:url" content="http://git-preprod-str.str-np-cluster-130016-d49ed5d9acfe3ceefe5258366bb16b0a-0000.us-east.containers.appdomain.cloud/" />
    <meta property="og:description" content="Gitea (Git with a cup of tea) is a painless self-hosted Git service written in Go">
    <div class="full height">
            <noscript>This website works better with JavaScript</noscript>




                    <div class="ui top secondary stackable main menu following bar light">
                            <div class="ui container" id="navbar">
                                    <div class="item brand" style="justify-content: space-between;">
                                            <a href="/" href="/">
                                                    <img class="ui mini image" src="/img/gitea-sm.png">
                                            </a>
                                            <div class="ui basic icon button mobile-only" id="navbar-expand-toggle">
                                                    <i class="sidebar icon"></i>
                                            </div>
                                    </div>


                                            <a class="item" href="/">Home</a>


                                    <a class="item" href="/explore/repos">Explore</a>







                                            <a class="item" target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io">Help</a>
                                            <div class="right stackable menu">

                                                            <a class="item" href="/user/sign_up">
                                                                    <i class="octicon octicon-person"></i> Register
                                                            </a>

                                                    <a class="item" href="/user/login?redirect_to=%2f%2fuser%2fsign_up">
                                                            <i class="octicon octicon-sign-in"></i> Sign In
                                                    </a>
                                            </div>


                            </div>
                    </div>

404


Application Version: 1.4.2

If you think this is an error, please open an issue on GitHub.

    </div>



    <footer>
            <div class="ui container">
                    <div class="ui left">
                            © Gitea Version: 1.4.2 Page: <strong>22ms</strong> Template: <strong>0ms</strong>
                    </div>
                    <div class="ui right links">

                            <div class="ui language bottom floating slide up dropdown link item">
                                    <i class="world icon"></i>
                                    <div class="text">English</div>
                                    <div class="menu">

                                                    <a class="item active selected" href="#">English</a>

                                                    <a class="item " href="//user/sign_up?lang=zh-CN">简体中文</a>

                                                    <a class="item " href="//user/sign_up?lang=zh-HK">繁體中文(香港)</a>

                                                    <a class="item " href="//user/sign_up?lang=zh-TW">繁體中文(台灣)</a>

                                                    <a class="item " href="//user/sign_up?lang=de-DE">Deutsch</a>

                                                    <a class="item " href="//user/sign_up?lang=fr-FR">français</a>

                                                    <a class="item " href="//user/sign_up?lang=nl-NL">Nederlands</a>

                                                    <a class="item " href="//user/sign_up?lang=lv-LV">latviešu</a>

                                                    <a class="item " href="//user/sign_up?lang=ru-RU">русский</a>

                                                    <a class="item " href="//user/sign_up?lang=uk-UA">Українська</a>

                                                    <a class="item " href="//user/sign_up?lang=ja-JP">日本語</a>

                                                    <a class="item " href="//user/sign_up?lang=es-ES">español</a>

                                                    <a class="item " href="//user/sign_up?lang=pt-BR">português do Brasil</a>

                                                    <a class="item " href="//user/sign_up?lang=pl-PL">polski</a>

                                                    <a class="item " href="//user/sign_up?lang=bg-BG">български</a>

                                                    <a class="item " href="//user/sign_up?lang=it-IT">italiano</a>

                                                    <a class="item " href="//user/sign_up?lang=fi-FI">suomi</a>

                                                    <a class="item " href="//user/sign_up?lang=tr-TR">Türkçe</a>

                                                    <a class="item " href="//user/sign_up?lang=cs-CZ">čeština</a>

                                                    <a class="item " href="//user/sign_up?lang=sr-SP">српски</a>

                                                    <a class="item " href="//user/sign_up?lang=sv-SE">svenska</a>

                                                    <a class="item " href="//user/sign_up?lang=ko-KR">한국어</a>

                                    </div>
                            </div>
                            <a href="/vendor/librejs.html" data-jslicense="1">JavaScript licenses</a>
                            <a href="/api/swagger">API</a>
                            <a target="_blank" rel="noopener" href="https://gitea.io">Website</a>
                            <span class="version">Go1.10</span>
                    </div>
            </div>
    </footer>
    <script src="/vendor/plugins/jquery/jquery.min.js"></script>
    <script src="/vendor/plugins/jquery.areyousure/jquery.are-you-sure.js"></script>
    <script src="/vendor/plugins/autolink/autolink.js"></script>
    <script src="/vendor/plugins/emojify/emojify.min.js"></script>
    <script src="/vendor/plugins/clipboard/clipboard.min.js"></script>
    <script src="/vendor/plugins/vue/vue.min.js"></script>
    <script src="/vendor/plugins/semantic/semantic.min.js"></script>
    <script src="/js/index.js?v=17b7ffb6cc1f3588d20dda49ffb651f0"></script>

You can skip the cookie part in the curl command. When I try to create an admin user with the credentials you put there I get the error that the password isn’t complex enough.

curl --request POST --url http://localhost:3000/user/sign_up --header 'content-type: application/x-www-form-urlencoded' --data user_name=gituser9 --data email=gituser9@git.com --data password=Gituser9_ --data retype=Gituser9_

this would work for example.

The initial setup is done?