Create GitHub Page via REST API v3

Hello everyone,

is it possible to create a new Github Page through the REST API v3?

I tried to use “Request a page build”, but it only works on already existing pages. If I use this endpoint for repositories where no page exists yet, I get this:

Status: 403 Forbidden

{
	"message": "The repository does not have a GitHub Pages site. See https://developer.github.com/v3/repos/pages/",
	"documentation_url": "https://developer.github.com/v3/repos/pages/#request-a-page-build"
}

Do you have some ideas?

Thanks in advance!

1 Like

If you want to enable Pages for a given repository, you have to tell it which branch (and optionally if you want to use the /docs directory) to build the Pages site from. (Just like you would have to do through the web UI.) You can do this with the Update information about a Pages site endpoint.

I hope that helps!

2 Likes

Hey @lee-dohm,

thanks for your reply, it sounds very useful!

I will try this and keep you updated!

1 Like

I tried your solution, but this endpoint also seems to work only with already existing pages.

If I create a new repository and upload a new index.html, I get a 404 Not Found at this endpoint.

And witch witch value should I send for “cname”? Is it [username].github.io ?

If the edit endpoint doesn’t offer what you want, then you’ll have to use the UI to initially enable Pages support for the repo. You probably shouldn’t be changing the CNAME value via the API but rather follow the system described in the help.