12

I am making a request to the below URL- Post https://api.github.com/repos/kvimal/2048/issues With my Token as a header for authorization.

The Curl Request

curl -i -X POST https://api.github.com/repos/kvimal/2048/issues  -d "{title:'hey'}" -H "Authorization: Bearer xxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json"

And GitHub sends a response 404 Not found. I have reade the Documentation and as far as i have observed i am doing it by the github standards. Can anyone Help with this issues?

Vimal
  • 189
  • 1
  • 3
  • 13
  • Please post your *code* for us to help with. If you are getting 404 errors, you are trying to access a URL that doesn't exist. – Martijn Pieters Mar 09 '15 at 07:30
  • The above mentioned Url is the one i am trying to make a request to. – Vimal Mar 09 '15 at 07:32
  • But the above URL *doesn't* return a 404. It works just fine. Your code obviously doesn't, so please share it. – Martijn Pieters Mar 09 '15 at 07:33
  • sure i have edited my above post. With a curl request – Vimal Mar 09 '15 at 07:34
  • And do you get a 404 with the `curl` request? How does this relate to Python at all now? – Martijn Pieters Mar 09 '15 at 07:38
  • I have a backend code in python that parses the json url request i make to, which is in python. Sorry for the wrong tags – Vimal Mar 09 '15 at 07:39
  • 1
    may not be actual answer but this may help someone.. in my case the issue was permission to the access token key created in git. I granted write package to key and it worked fine. Before that the error was 404 resource/file was not found at location.. (mostly due to security) (I wanted to add it as comment but not yet it seems) – granthik Nov 10 '20 at 14:34

3 Answers3

11

As illustrated in this python script, the header should be using 'token' not Bearer'

headers = {
  'Content-Type':'application/json',
  'Authorization': 'token %s' % token,
} 

(That script doesn't use curl, but give an idea of the header)

For curl queries, see this curl POST tutorial:

curl -H "Authorization: token OAUTH-TOKEN"

And the POST message must be complete as well (as in this python script)

issue = {'title': title,
         'body': body,
         'assignee': assignee,
         'milestone': milestone,
         'labels': labels}
# Add the issue to our repository
r = session.post(url, json=issue)

(again, not curl, but gives you an example of the body)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    Ah, indeed, see [this section in the documentation](https://developer.github.com/v3/auth/#basic-authentication); the API responds with 404 Not Found to not reveal private repositories. – Martijn Pieters Mar 09 '15 at 07:45
  • @MartijnPieters I agree, but https://github.com/kvimal/2048 is a public repo, is it not? – VonC Mar 09 '15 at 07:46
  • A direct unauthenticated GET request certainly works, but for consistency the API may still use 404 to respond to invalidly authenticated requests. – Martijn Pieters Mar 09 '15 at 07:48
  • @MartijnPieters that I understand, which is why I was pointing out the strange content of the header `Authorization: Bearer`. – VonC Mar 09 '15 at 07:51
  • Github is probably first trying to parse the `Authorization` header for the `token xxxx` form, and if that fails, falls back to expecting `Authorization: Basic`. If the latter fails then a 404 is returned. – Martijn Pieters Mar 09 '15 at 08:02
  • Thanks, it worked. I had to send the request , with form details in a json format. – Vimal Mar 09 '15 at 09:20
8

Go to "Edit personal access token" page, checkout the "Select scopes" session.

Make sure the token has been granted required access right.

I encountered similar case when trying to create public repo with 'Authorization: token ...' header.

Beeno Tung
  • 1,058
  • 10
  • 17
  • 3
    This was issue for me. Shoutouts to GitHub for not adding any 'you lack permission' text in the response, sending us on this wild goose chase in the first place... – 1owk3y Jul 27 '22 at 12:48
  • Thank you. It works after I add `public_repo` permission. – Hunger Feb 24 '23 at 03:02
0

I want to scream so bad right now!

If you leave an extra slash at the end of the graphql url then you will get a 404 error.

https://api.github.com/graphql is safe

https://api.github.com/graphql/ is a 404 error with no details.

I have spent the last 2 hours knowing my token or headers or query wasn't wrong and I was right! That little slash of hell will end you....