Need a graphql mutation example for creating a repository

I’m looking for a good example of how to create a repository with graphql. The docs would seem to suggest doing something like this …

mutation CreateRepositoryPayload {
  createRepository (input: {
    	name: "MyNewRepo",
		visibility: INTERNAL
  	}) {
    repository {

That, of course, results in an error. I find it remarkable that the organization name does not seem to be required field of the CreateRepositoryInput. Can anyone provide me a working example before I throw in the towel and go back to the REST API?

Steve Maring


Welcome to the GitHub Community!!

You need to first get the organization/repositoryOwner id to create a repo.

Below is an example to fetch the id

I have updated your GraphQL query with the ownerId parameter.

The repository will be created.

Parithiban G

Thanks for the clarification @parithiban ! That’s very helpful. Since I’m trying to make a repo under an organization I’ll just use the org id as the ownerId.

1 Like