Creating PR results in 404 error?

I’d like to create Pull Requests via API (using PyGithub as implementation). For testing, I’m making a PR inside my repository from branch mass-update-1 to develop.

Repository exists:

$ curl -u iarspider -i https://api.github.com/repos/iarspider/spack

HTTP/1.1 200 OK

(...)

Branches exist:

$ curl -u iarspider -i https://api.github.com/repos/iarspider/spack/branches/mass-update-1
HTTP/1.1 200 OK

(...)


$ curl -u iarspider -i https://api.github.com/repos/iarspider/spack/branches/develop
HTTP/1.1 200 OK

(...)

But creating a PR results in 404:

$ curl -X POST -d '{"title": "Add extra version of expat", "body": "Split from #14570", "base": "develop", "head": "mass-update-1"}' -H "Content-Type: application/json" -u iarspider -i https://api.github.com/repos/iarspider/spack/pulls


HTTP/1.1 404 Not Found
Date: Fri, 14 Feb 2020 10:43:47 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 116
Server: GitHub.com
Status: 404 Not Found
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4951
X-RateLimit-Reset: 1581677662
X-OAuth-Scopes:
X-Accepted-OAuth-Scopes:
X-GitHub-Media-Type: github.v3; format=json
Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type
Access-Control-Allow-Origin: *
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Frame-Options: deny
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
Content-Security-Policy: default-src 'none'
Vary: Accept-Encoding, Accept, X-Requested-With
X-GitHub-Request-Id: A4FA:5C8F:A25DE:C513C:5E4679E3

{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/pulls/#create-a-pull-request"
}
1 Like

Hey, the first step I would try would be to swap the order of “base” and “head” to match up with the API’s example directly. Let me know if that does not work. 

Nope, same 404 error:

$ curl -X POST -d '{"title": "Add extra version of expat", "body": "Split from #14570", "head": "mass-update-1", "base": "develop"}' -H "Content-Type: application/json" -u iarspider -i https://api.github.com/repos/iarspider/spack/pulls

HTTP/1.1 404 Not Found
Date: Fri, 14 Feb 2020 14:37:27 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 116
Server: GitHub.com
Status: 404 Not Found
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
X-RateLimit-Reset: 1581694647
X-OAuth-Scopes:
X-Accepted-OAuth-Scopes:
X-GitHub-Media-Type: github.v3; format=json
Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type
Access-Control-Allow-Origin: *
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Frame-Options: deny
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
Content-Security-Policy: default-src 'none'
Vary: Accept-Encoding, Accept, X-Requested-With
X-GitHub-Request-Id: EBEC:2D3DF:64A6B7:7A2C41:5E46B0A7

{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3/pulls/#create-a-pull-request"
}
1 Like

I think the issue may be that you aren’t authenticated. I am pretty sure you need to use a GitHub Personal Access token in order to do what you’re trying to do (since theoretically right now all you are providing is a user name, which anyone who sees’s your public repo could access and subsequently make the same API request as you). The 404 is likely saying “hey, someone is trying to access this command without telling us who they really are so we don’t want to get involved in that. Let’s tell them as little as possible (for security reasons) and return a 404”. 

https://developer.github.com/v3/guides/getting-started/#authentication

I am using personal token, I’m just not showing it.

1 Like

It is possible your Personal Access Token does not have the correct permissions set to write to the repo. I suggest checking your current permissions.

Yup, had to add “access public repositories” to the token. Wish it was documented somewhere :slight_smile:

1 Like