23
votes

I would like to get a list of public gists in Postman. I can do curl https://api.github.com/gists/public in my command line which works fine.

However I did not manage to find out how to do the same in Postman.

I tried to make a GET request at https://api.github.com/gists/public which returned the following object:

{
  "message": "Bad credentials",
  "documentation_url": "https://developer.github.com/v3"
}

I find it confusing to not to be required to authenticate when making the request from command line but when I would like to do basically the same from Postman it throws an error. But ok, I tried to authenticate myself.

I have created an OAuth application in my GitHub so I recieved a Client ID and Client Secret.

I have tried to pass these to my requests as query params / header information / and also as part of the body without any success.

I also have tried to use the web application flow (https://developer.github.com/v3/oauth/#web-application-flow), and tried to create a new authorization with sending a POST request to https://api.github.com/authorizations with my User ID and User Secret in it (https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization), which returned

{
  "message": "Requires authentication",
  "documentation_url": "https://developer.github.com/v3/oauth_authorizations/#oauth-authorizations-api"
}

Now I am super confused about what should generate my token, and where should I pass it to. All I want is some public information (public gists) in Postman, the same as in command line.

1

1 Answers

30
votes

Using the header method, you should be able to put "Authorization: token OAUTH-TOKEN" directly into the key input under the Headers section.

Obviously replace OAUTH-TOKEN with your actual token.

Edit: The above is correct, but I found it non obvious. The image shows what to do, (a) in the key field, put in 'Authorization', (b) in the value field, put in 'token '.

Looking at it in curl, it add -H "Authorization: token <your token here>" to the request, which is what is needed.

Postman GET to github API with Oauth authentication