# Howto create repository using api

**URL:** <https://forum.gitea.com/t/howto-create-repository-using-api/3821>\
**Category:** API/SDK/Tea/HelmChart/Terraform\
**Created:** [September 24, 2021, 2:59pm UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821 "2021-09-24T14:59:50Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmonty14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/cmonty14/32/1627_2.png) [@cmonty14](https://forum.gitea.com/u/cmonty14)\
**Post date:** [September 24, 2021, 2:59pm UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/1 "2021-09-24T14:59:51Z")

</div>

Hello,  
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"}' https://api.github.com/user/repos`

Please advise.

THX

---

<div class="post-metadata">

**Author:** ![techknowlogick](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/techknowlogick/32/4706_2.png) [@techknowlogick](https://forum.gitea.com/u/techknowlogick)\
**Post date:** [September 25, 2021, 3:25pm UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/2 "2021-09-25T15:25:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cmonty14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/cmonty14/32/1627_2.png) [@cmonty14](https://forum.gitea.com/u/cmonty14)\
**Post date:** [September 28, 2021, 7:31am UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/3 "2021-09-28T07:31:37Z")

</div>

Hello,  
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](https://cli.github.com/) another option for this use case?

---

<div class="post-metadata">

**Author:** ![dachary](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/dachary/32/4990_2.png) [@dachary](https://forum.gitea.com/u/dachary)\
**Post date:** [September 29, 2021, 5:34am UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/4 "2021-09-29T05:34:55Z")

</div>

I don’t think the github cli will work. The [documentation page](https://docs.gitea.io/en-us/api-usage/#generating-and-listing-api-tokens) will provide you with the information you need regarding the token.

---

<div class="post-metadata">

**Author:** ![cmonty14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/cmonty14/32/1627_2.png) [@cmonty14](https://forum.gitea.com/u/cmonty14)\
**Post date:** [September 29, 2021, 8:44am UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/5 "2021-09-29T08:44:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dachary](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/dachary/32/4990_2.png) [@dachary](https://forum.gitea.com/u/dachary)\
**Post date:** [September 29, 2021, 4:13pm UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/6 "2021-09-29T16:13:03Z")

</div>

> [@cmonty14](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![techknowlogick](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/techknowlogick/32/4706_2.png) [@techknowlogick](https://forum.gitea.com/u/techknowlogick)\
**Post date:** [September 30, 2021, 2:51am UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/7 "2021-09-30T02:51:07Z")

</div>

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](https://gitea.com/gitea/tea/)

---

<div class="post-metadata">

**Author:** ![cmonty14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/cmonty14/32/1627_2.png) [@cmonty14](https://forum.gitea.com/u/cmonty14)\
**Post date:** [October 1, 2021, 12:40pm UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/8 "2021-10-01T12:40:13Z")

</div>

Nice.  
Many thanks for sharing this information.

---

<div class="post-metadata">

**Author:** ![strativab](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/strativab/32/1529_2.png) [@strativab](https://forum.gitea.com/u/strativab)\
**Post date:** [October 6, 2021, 9:43am UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/9 "2021-10-06T09:43:35Z")

</div>

Thanks for such information.

---

<div class="post-metadata">

**Author:** ![cmonty14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/cmonty14/32/1627_2.png) [@cmonty14](https://forum.gitea.com/u/cmonty14)\
**Post date:** [October 28, 2021, 4:09pm UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/10 "2021-10-28T16:09:39Z")

</div>

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:  
`{"message":"Required","url":"https://<my-gitea-url>/api/swagger"}`

Can you please advise how to fix this?

THX

---

<div class="post-metadata">

**Author:** ![dachary](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/dachary/32/4990_2.png) [@dachary](https://forum.gitea.com/u/dachary)\
**Post date:** [October 28, 2021, 5:18pm UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/11 "2021-10-28T17:18:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cmonty14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/cmonty14/32/1627_2.png) [@cmonty14](https://forum.gitea.com/u/cmonty14)\
**Post date:** [October 29, 2021, 5:57am UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/12 "2021-10-29T05:57:53Z")

</div>

Thanks for your reply.

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

```auto
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.  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/gitea/original/2X/3/3d985670e1a7d05bdb4acc5a3d5d91a35799b453.png)

How can I create a repository belonging to specific organization _etckeeper_?  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/gitea/original/2X/6/665795f9dcf80631880e3c281f223b3ee1353518.png)

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

---

<div class="post-metadata">

**Author:** ![dachary](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/dachary/32/4990_2.png) [@dachary](https://forum.gitea.com/u/dachary)\
**Post date:** [October 29, 2021, 6:16pm UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/13 "2021-10-29T18:16:41Z")

</div>

> [@cmonty14](#):
>
> `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`

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

---

<div class="post-metadata">

**Author:** ![cmonty14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/cmonty14/32/1627_2.png) [@cmonty14](https://forum.gitea.com/u/cmonty14)\
**Post date:** [October 30, 2021, 8:14am UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/14 "2021-10-30T08:14:27Z")

</div>

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"}' https://api.github.com/orgs/ORGANIZATION_NAME/repos`

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.

---

<div class="post-metadata">

**Author:** ![strativab](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/strativab/32/1529_2.png) [@strativab](https://forum.gitea.com/u/strativab)\
**Post date:** [November 3, 2021, 10:37am UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/15 "2021-11-03T10:37:21Z")

</div>

Thanks For Sharing this source.

---

<div class="post-metadata">

**Author:** ![cmonty14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/cmonty14/32/1627_2.png) [@cmonty14](https://forum.gitea.com/u/cmonty14)\
**Post date:** [November 3, 2021, 6:43pm UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/16 "2021-11-03T18:43:32Z")

</div>

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

```auto
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).

---

<div class="post-metadata">

**Author:** ![strativab](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/strativab/32/1529_2.png) [@strativab](https://forum.gitea.com/u/strativab)\
**Post date:** [November 29, 2021, 9:07am UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/17 "2021-11-29T09:07:12Z")

</div>

Dont share your acess token publicly. Thanks

---

<div class="post-metadata">

**Author:** ![msillence](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@msillence](https://forum.gitea.com/u/msillence)\
**Post date:** [October 12, 2023, 5:38am UTC](https://forum.gitea.com/t/howto-create-repository-using-api/3821/19 "2023-10-12T05:38:47Z")

</div>

for user repos this works:

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

```

you need both the Auth and the content type headers
