Search code examples
githubgithub-api

How to create user repository via GitHub App API?


A user installed my github app for his personal account (not organization). My github app has read & write administration permissions.

When I perform the request (I use go-github sdk) I get the following error:

POST https://api.github.com/user/repos: 403 Resource not accessible by integration []

There are two different endpoints for creating repositories in organization and for user. Endpoint for creating user repos is the POST method /user/repos. When I look github official documentation on github app permissions it doesn't actually list POST method for user/repos. So it's not clear how to create user repos via github app, if possible at all.


Solution

  • I got a response from github support. This behaviour is expected. To create new repos under a user you have to use user-to-server token (oauth2 token). It can be acquired during installation if you enable option "Request user authorization (OAuth) during installation" in your github app. This way user not only install your github app but also will authorize your github app.