Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 5

Create GitHub Page via REST API v3

Solved! Go to Solution.

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!

 

4 Replies
Moderator
Message 2 of 5

Re: Create GitHub Page via REST API v3

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!

Copilot Lvl 3
Message 3 of 5

Re: Create GitHub Page via REST API v3

Hey @lee-dohm,

thanks for your reply, it sounds very useful!

I will try this and keep you updated!

Copilot Lvl 3
Message 4 of 5

Re: Create GitHub Page via REST API v3

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 ?

 

Solution
Moderator
Message 5 of 5

Re: Create GitHub Page via REST API v3

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.