Integrate and explore the GitHub REST API using curl and Postman. This project provides real-world examples of API authentication, core endpoint usage (repos, issues, starring), and error handling. Includes reusable curl scripts, a Postman collection, and a clear step-by-step guide for developers, testers, and technical writers.
github-api-guide/
├── postman_collection.json
│ ├── create-issue.sh
│ ├── create-repo.sh
│ ├── get-user.sh
│ ├── list-repos.sh
│ └── star-repo.sh
├── assets/
│ └── postman-auth-example.png
├── docs/
│ ├── index.md
│ └── _config.yml
├── README.md
└── LICENSE
- Go to GitHub → Settings → Developer Settings → Personal access tokens → Fine-grained tokens or Tokens (classic)
- Click "Generate new token"
- Select scopes:
repo
(for repo access)user
(to access user data)workflow
(for GitHub Actions, optional)
- Copy the token (e.g.
ghp_YFjQVBHMJ2tZZpkw6i...
) and store it securely.
curl -H "Authorization: token YOUR_GITHUB_TOKEN" \
https://api.github.com/user
{
"login": "your-username",
"id": 201234561,
"public_repos": 42,
"public_gists": 13,
...
}
{
"message": "Bad credentials",
"documentation_url": "https://docs.github.com/rest",
"status": "401"
}
-
Create a new GET request to:
https://api.github.com/user
-
Under the Authorization tab:
- Type: Bearer Token
- Token:
YOUR_GITHUB_TOKEN
-
Click Send → You should see your user profile response.
GET /user/repos
curl:
curl -H "Authorization: token YOUR_GITHUB_TOKEN" \
https://api.github.com/user/repos
Use case: Get a list of all repositories you own or have access to.
GET /repos/:owner/:repo
curl:
curl -H "Authorization: token YOUR_GITHUB_TOKEN" \
https://api.github.com/repos/octocat/Hello-World
POST /user/repos
curl:
curl -X POST https://api.github.com/user/repos \
-H "Authorization: token YOUR_GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"test-repo-from-api","private":false}'
POST /repos/:owner/:repo/issues
curl:
curl -X POST https://api.github.com/repos/YOUR_USERNAME/YOUR_REPO/issues \
-H "Authorization: token YOUR_GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d '{"title":"Bug report","body":"There is a bug here."}'
PUT /user/starred/:owner/:repo
curl:
curl -X PUT -H "Authorization: token YOUR_GITHUB_TOKEN" \
-H "Content-Length: 0" \
https://api.github.com/user/starred/octocat/Hello-World
Understanding how the GitHub API responds, especially in error scenarios, is key for debugging and robust integration.
Most GitHub API responses on success return:
-
200 OK for GET or PUT
-
201 Created for POST
-
JSON body with relevant data
HTTP/1.1 200 OK
Content-Type: application/json
{
"login": "your-username",
"id": 1234567,
"name": "Your Name",
"public_repos": 12,
...
}
Status | Cause | How to Fix |
---|---|---|
401 | Unauthorized (Bad Token) | Check Authorization header or token scopes |
403 | Forbidden (Rate Limit or Scopes) | Wait for reset or adjust token permissions |
404 | Not Found (Wrong URL or Repo) | Check owner/repo names and auth context |
422 | Validation Failed (Bad payload) | Fix JSON body, ensure required fields present scopes |
500 | Server Error | Retry later (GitHub issue) |
curl -H "Authorization: token invalid_token" https://api.github.com/user
{
"message": "Bad credentials",
"documentation_url": "https://docs.github.com/rest"
}
GitHub API uses two types of rate limits:
-
Unauthenticated: 60 requests/hour
-
Authenticated: 5000 requests/hour (with token)
To check your rate limit:
curl -H "Authorization: token YOUR_GITHUB_TOKEN" \
https://api.github.com/rate_limit
{
"rate": {
"limit": 5000,
"remaining": 4998,
"reset": 1723782053
}
}
To convert reset
UNIX timestamp:
date -d @1723782053
- Use Tests tab to assert status codes:
pm.test("Status is 200", () => {
pm.response.to.have.status(200);
});
- Handle missing or invalid tokens:
if (pm.response.code === 401) {
console.warn("Unauthorized – Check your token!");
}
You can run demo API calls via CLI by using the scripts in /curl-scripts
.
Export your token before running any script:
export GITHUB_TOKEN=ghp_your_personal_access_token
Script | Description |
---|---|
get-user.sh | Get authenticated user info |
list-repos.sh | List all repos for user |
create-repo.sh | Create a new public repo |
create-issue.sh | Open an issue in a test repo |
star-repo.sh | Star a repo via curl |
Run with:
./curl-scripts/create-repo.sh test-repo
This project is licensed under the MIT License.