14

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?

7
  • 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. Commented Mar 9, 2015 at 7:30
  • The above mentioned Url is the one i am trying to make a request to. Commented Mar 9, 2015 at 7:32
  • But the above URL doesn't return a 404. It works just fine. Your code obviously doesn't, so please share it. Commented Mar 9, 2015 at 7:33
  • sure i have edited my above post. With a curl request Commented Mar 9, 2015 at 7:34
  • 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) Commented Nov 10, 2020 at 14:34

3 Answers 3

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)

Sign up to request clarification or add additional context in comments.

6 Comments

Ah, indeed, see this section in the documentation; the API responds with 404 Not Found to not reveal private repositories.
@MartijnPieters I agree, but github.com/kvimal/2048 is a public repo, is it not?
A direct unauthenticated GET request certainly works, but for consistency the API may still use 404 to respond to invalidly authenticated requests.
@MartijnPieters that I understand, which is why I was pointing out the strange content of the header Authorization: Bearer.
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.
|
11

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.

2 Comments

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...
Thank you. It works after I add public_repo permission.
1

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....

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.