Unable to create reference as a Github App [Resource not accessible by integration]

Basically I need my App to be able to create/delete branches, but I can’t get it to work. I don’t need to do these actions on behalf of the user, so if there’s a a way of doning this using an installation access token, that would be great.

Right now I hve tried with installation tokens, and user token, noth work with other endpoints (GET refs, GET commits, …) but with the create referene one, I get this error message: Resource not accessible by integration.

I thought the user access token will work but it didn’t, so I guess I’m doing something wrong, but I can’t identify what it is. Also if this is the only way, how long does a user token lasts? Can I use the same code from the authorization response to get a new one?

Any help would be appreciated. Some information below…

POST https://api.github.com/repos/ORG/REPO/git/refs

Accept: application/vnd.github.machine-man-preview+json  
Authorization: token \<I tried with installation and user tokens here\>  

	"ref": "refs/heads/test",
	"sha": "aa12ee25...."

403 Forbidden
"message": "Resource not accessible by integration",
"documentation_url": "https://developer.github.com/v3/git/refs/#create-a-reference"

Ok, it seems like the issue only applies to private repositories, it works fine for public ones using the installation token. Not sure if there is a limitation here or I’m missing some configuration on my app to include private repositories.

Again, any feedback would be appreciated, I’m running out of ideas…

Nevermind. Already fixed it. It seems like “Repository metadata” permissions is needed to do this operations on private repos…

1 Like