# Using API to Create A Repo On Behalf of Someone

**URL:** <https://forum.gitea.com/t/using-api-to-create-a-repo-on-behalf-of-someone/3477>\
**Category:** API/SDK/Tea/HelmChart/Terraform\
**Created:** [July 7, 2021, 8:24pm UTC](https://forum.gitea.com/t/using-api-to-create-a-repo-on-behalf-of-someone/3477 "2021-07-07T20:24:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dvw](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dvw](https://forum.gitea.com/u/dvw)\
**Post date:** [July 7, 2021, 8:24pm UTC](https://forum.gitea.com/t/using-api-to-create-a-repo-on-behalf-of-someone/3477/1 "2021-07-07T20:24:39Z")

</div>

We need to create a repository using an existing repo template on behalf of a user. Is the /user/repos POST a right API ? We don’t see a field related with an existing template repo in its request body.

Update:

I just find this API /admin/users/{username}/repos POST for creating a repository on behalf of a user. I, however, still don’t see how that uses an existing repo.

---

<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:** [July 15, 2021, 5:40pm UTC](https://forum.gitea.com/t/using-api-to-create-a-repo-on-behalf-of-someone/3477/2 "2021-07-15T17:40:50Z")

</div>

I believe this was answered in discord, but for others searching for this topic you would use the standard repo template endpoint (check swagger for exact path), then you’d use sudo header to be able to act as someone else.

---

<div class="post-metadata">

**Author:** ![dvw](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dvw](https://forum.gitea.com/u/dvw)\
**Post date:** [July 15, 2021, 6:57pm UTC](https://forum.gitea.com/t/using-api-to-create-a-repo-on-behalf-of-someone/3477/3 "2021-07-15T18:57:59Z")

</div>

Thanks. You are right. This question has been answered on Discord.

---

<div class="post-metadata">

**Author:** ![dvw](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dvw](https://forum.gitea.com/u/dvw)\
**Post date:** [September 9, 2021, 5:35pm UTC](https://forum.gitea.com/t/using-api-to-create-a-repo-on-behalf-of-someone/3477/4 "2021-09-09T17:35:50Z")

</div>

Here are log messages of an API call:

On the Gitea:

```auto
2021/09/09 09:59:57 Started POST /api/v1/repos/my-admin/my-code-template/generate?sudo=user-123 for 127.0.0.1:53502
2021/09/09 09:59:57 Completed POST /api/v1/repos/my-admin/my-code-template/generate?sudo=user-123 404 Not Found in 3.983329ms

```

On a client:

```auto
2021-09-09 09:59:56.988 DEBUG 88445 --- [XNIO-1 task-2] c.i.c.reposetup.web.rest.GiteaClient : ::: generate repo with sudo: GenerateRepoOption{avatar=true, description='null', gitContent=true, gitHooks=true, labels=true, name='my-code-repo', owner='user-123', _private=false, topics=true, webhooks=true} with repo template: my-code-template of user: my-admin
2021-09-09 09:59:56.998 DEBUG 88445 --- [XNIO-1 task-2] c.i.c.reposetup.web.rest.GiteaClient : {"avatar":true,"git_content":true,"git_hooks":true,"labels":true,"name":"my-code-repo","owner":"user-123","private":false,"topics":true,"webhooks":true}
2021-09-09 09:59:57.009 ERROR 88445 --- [XNIO-1 task-2] c.i.c.reposetup.web.rest.GiteaClient : Response{protocol=http/1.1, code=404, message=Not Found, url=http://localhost:3000/api/v1/repos/my-admin/my-code-template/generate?sudo=user-123}
2021-09-09 09:59:57.009 ERROR 88445 --- [XNIO-1 task-2] c.i.c.reposetup.web.rest.GiteaClient : Not Found

```

The request is submitted by an admin user. And the template owner, template repo, the owner of the repo are all there.

Also, the same request without sudo can be invoked successfully either by the admin user to generate the repo for himself or by the new repo owner.

Any possible reasons for the “Not Found” error?
