Howto create repository using api

can you please advise how to create a repository from any server that is not hosting gitea?

I have found this but I’m not sure how this should be applied with gitea.
curl -H "Authorization: token ACCESS_TOKEN" --data '{"name":"NEW_REPO_NAME"}'

Please advise.


1 Like

The URL you are using is for Github, but if you use the route /api/v1/user/repos and referencing your gitea URL with the same information then a new repo would be created.

1 Like

thanks for your reply.

Could you please advise for the complete syntax of the command to be executed?
curl -H "Authorization: token ACCESS_TOKEN" --data '{"name":"NEW_REPO_NAME"}' https://<my-gitea-url>/api/v1/user/repos
Where can I find the relevant token?
And is tool github cli another option for this use case?

1 Like

I don’t think the github cli will work. The documentation page will provide you with the information you need regarding the token.

Why don’t you think that github cli will work?
Is this tool restricted to usage with GitHub?

Yes, I don’t think it is suited to deal with the small differences between the GitHub and Gitea API.

There is a specific Gitea CLI gitea/tea: A command line tool to interact with Gitea servers - tea - Gitea: Git with a cup of tea

1 Like

Many thanks for sharing this information.

1 Like

Thanks for such information.

I have created a token in Gitea installation’s web interface and executed this command:
curl -k -H "Authorization: token <my-access-token-generated-in-webui>" --data '{"name":"<unique-name>"}' https://<my-gitea-url>/api/v1/user/repos

The output is this:

Can you please advise how to fix this?


You are missing the -H “content-type: application/json” argument (curl will, by default, set it to content-type: application/x-www-form-urlencoded)

1 Like

Thanks for your reply.

I have executed the following command and get a new error now:

curl -k -H "content-type: application/json" "Authorization: token <my-access-token-generated-in-webui>" --data '{"name":"<unique-name>"}' https://<my-gitea-url>/api/v1/user/repos

curl: (3) URL using bad/illegal format or missing URL
{"message":"token is required","url":"https://<my-gitea-url/api/swagger"}

After modifying the syntax the repository is created accordingly:
curl -k -H "content-type: application/json" -H "Authorization: token <my-access-token-generated-in-webui>" --data '{"name":"<unique-name>"}' https://<my-gitea-url>/api/v1/user/repos

However, the repository is created under the wrong organization, means the organization is the relevant user account. Instead the organization should be etckeeper.
Please check screenshot for details.

How can I create a repository belonging to specific organization etckeeper?

My intention is to have a hierarchy with etckeeper on top an all clients pushing data to its relevant repository identified by FQDN.

You are missing a -H before "Auth… now.

I have corrected my syntax and posted this in my reply on Oct. 29 already.
However I want the newly created repository to be created under a specific organization (here: etckeeper).
Please check the screenshots in my previous posting.

In Github, the relevant command would be:
curl -H "Authorization: token ACCESS_TOKEN" --data '{"name":"NEW_REPO_NAME"}'

What is the relevant syntax for Gitea?

Or would it make sense to use a specific user account, e.g. etckeeper, instead?
Then I would not need to create a hierarchy with Organization > Repository.

1 Like

Thanks For Sharing this source.

In the meantime I found the correct syntax for Gitea; please check this:

curl -k -X POST "https://<gitea-url>/api/v1/org/<organization>/repos" -H "content-type: application/json" -H "Authorization: token 45647956a7434b47c04b47c69579fb0123456789" --data '{"name":"<repo-name>"}'

This is working for me (on +100 installations).


Dont share your acess token publicly. Thanks

for user repos this works:

curl -k  -H "content-type: application/json"  -H "Authorization: token <token>" 'https://<>/api/v1/user/repos' -d '{"name": "<reponame>"}'

you need both the Auth and the content type headers