Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use GitHub API in Postman

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.

like image 982
Gábor Pintér Avatar asked Nov 15 '16 19:11

Gábor Pintér


People also ask

How do I authenticate GitHub API in Postman?

Go to your user profile and select Access Tokens . Give your new token a name that makes sense to use and select the api scope. This access token will be shown only once. How that the token has been created, copy it, and let's added it to the Postman request.


1 Answers

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

like image 147
Scott P Avatar answered Sep 25 '22 19:09

Scott P