{"id":31126722,"url":"https://github.com/anthony-reese/github-api-guide","last_synced_at":"2025-09-17T23:02:06.605Z","repository":{"id":310726885,"uuid":"1040769020","full_name":"anthony-reese/github-api-guide","owner":"anthony-reese","description":"Hands-on GitHub REST API walkthrough with curl, Postman, and response handling","archived":false,"fork":false,"pushed_at":"2025-08-19T21:32:39.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-19T22:26:12.747Z","etag":null,"topics":["api-documentation","api-examples","api-integration","api-testing","authentication","bash-scripts","curl","developer-tools","error-handling","github-api","http-client","json","personal-access-token","postman","rest-api","technical-writing"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anthony-reese.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-19T13:32:57.000Z","updated_at":"2025-08-19T21:32:42.000Z","dependencies_parsed_at":"2025-08-19T22:36:20.034Z","dependency_job_id":null,"html_url":"https://github.com/anthony-reese/github-api-guide","commit_stats":null,"previous_names":["anthony-reese/github-api-guide"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/anthony-reese/github-api-guide","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthony-reese%2Fgithub-api-guide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthony-reese%2Fgithub-api-guide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthony-reese%2Fgithub-api-guide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthony-reese%2Fgithub-api-guide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anthony-reese","download_url":"https://codeload.github.com/anthony-reese/github-api-guide/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthony-reese%2Fgithub-api-guide/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275680446,"owners_count":25508570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-17T02:00:09.119Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-documentation","api-examples","api-integration","api-testing","authentication","bash-scripts","curl","developer-tools","error-handling","github-api","http-client","json","personal-access-token","postman","rest-api","technical-writing"],"created_at":"2025-09-17T23:00:52.080Z","updated_at":"2025-09-17T23:02:06.533Z","avatar_url":"https://github.com/anthony-reese.png","language":"Shell","readme":"# Integrating the GitHub API using curl and Postman\n\n![License](https://img.shields.io/github/license/anthony-reese/github-api-guide?style=flat-square\u0026cacheBust=1)\n![Stars](https://img.shields.io/github/stars/anthony-reese/github-api-guide?style=social)\n![Last Commit](https://img.shields.io/github/last-commit/anthony-reese/github-api-guide)\n\nIntegrate and explore the GitHub REST API using curl and Postman.\nThis 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.\n\n---\n\n## Project Structure\n```\ngithub-api-guide/\n├── postman_collection.json\n│   ├── create-issue.sh\n│   ├── create-repo.sh\n│   ├── get-user.sh\n│   ├── list-repos.sh\n│   └── star-repo.sh\n├── assets/\n│   └── postman-auth-example.png\n├── docs/\n│   ├── index.md\n│   └── _config.yml\n├── README.md\n└── LICENSE\n```\n\n## Setup \u0026 Authentication\n\n### 1. Create a GitHub Personal Access Token (PAT)\n\n1. Go to [GitHub → Settings → Developer Settings → Personal access tokens → Fine-grained tokens or Tokens (classic)](https://github.com/settings/tokens)\n2. Click **\"Generate new token\"**\n3. Select scopes:\n   - `repo` (for repo access)\n   - `user` (to access user data)\n   - `workflow` (for GitHub Actions, optional)\n4. Copy the token (e.g. `ghp_YFjQVBHMJ2tZZpkw6i...`) and store it securely.\n\n---\n\n### Test Authentication with curl\n\n```bash\ncurl -H \"Authorization: token YOUR_GITHUB_TOKEN\" \\\n     https://api.github.com/user\n```\n\n### Example Response\n```json\n{\n  \"login\": \"your-username\",\n  \"id\": 201234561,\n  \"public_repos\": 42,\n  \"public_gists\": 13,\n  ...\n}\n```\n\n### Example Error (Invalid Token)\n```json\n{\n  \"message\": \"Bad credentials\",\n  \"documentation_url\": \"https://docs.github.com/rest\",\n  \"status\": \"401\"\n}\n```\n\n### Test Authentication in Postman\n\n1. Create a new GET request to:\n    ```arduino\n    https://api.github.com/user\n    ```\n\n2. Under the **Authorization** tab:\n    - Type: **Bearer Token**\n    - Token: `YOUR_GITHUB_TOKEN`\n\n3. Click **Send** → You should see your user profile response.\n\n\n## Core API Use Cases\n\n### List Repositories for Authenticated User\n\n`GET /user/repos`\n\n**curl:**\n```bash\ncurl -H \"Authorization: token YOUR_GITHUB_TOKEN\" \\\n     https://api.github.com/user/repos\n```\n\n**Use case:** Get a list of all repositories you own or have access to.\n\n### Get a Specific Repository\n\n`GET /repos/:owner/:repo`\n\n**curl:**\n```bash\ncurl -H \"Authorization: token YOUR_GITHUB_TOKEN\" \\\n     https://api.github.com/repos/octocat/Hello-World\n```\n\n### Create a New Repository\n\n`POST /user/repos`\n\n**curl:**\n```bash\ncurl -X POST https://api.github.com/user/repos \\\n     -H \"Authorization: token YOUR_GITHUB_TOKEN\" \\\n     -H \"Content-Type: application/json\" \\\n     -d '{\"name\":\"test-repo-from-api\",\"private\":false}'\n```\n\n### Create an Issue\n\n`POST /repos/:owner/:repo/issues`\n\n**curl:**\n```bash\ncurl -X POST https://api.github.com/repos/YOUR_USERNAME/YOUR_REPO/issues \\\n     -H \"Authorization: token YOUR_GITHUB_TOKEN\" \\\n     -H \"Content-Type: application/json\" \\\n     -d '{\"title\":\"Bug report\",\"body\":\"There is a bug here.\"}'\n```\n\n### Star a Repository\n\n`PUT /user/starred/:owner/:repo`\n\n**curl:**\n```bash\ncurl -X PUT -H \"Authorization: token YOUR_GITHUB_TOKEN\" \\\n     -H \"Content-Length: 0\" \\\n     https://api.github.com/user/starred/octocat/Hello-World\n```\n\n## Response Handling \u0026 Error Cases\n\nUnderstanding how the GitHub API responds, especially in error scenarios, is key for debugging and robust integration.\n\n### Successful Response Example\n\nMost GitHub API responses on success return:\n\n- 200 OK for GET or PUT\n\n- 201 Created for POST\n\n- JSON body with relevant data\n\n### Example – Get Authenticated User:\n\n```http\nHTTP/1.1 200 OK\nContent-Type: application/json\n```\n\n```json\n{\n  \"login\": \"your-username\",\n  \"id\": 1234567,\n  \"name\": \"Your Name\",\n  \"public_repos\": 12,\n  ...\n}\n```\n\n### Common Error Responses\n\n| Status | Cause                            | How to Fix                                            |\n|--------|----------------------------------|-------------------------------------------------------|\n| 401    | Unauthorized (Bad Token)         | Check `Authorization` header or token scopes          |\n| 403    | Forbidden (Rate Limit or Scopes) | Wait for reset or adjust token permissions            |\n| 404    | Not Found (Wrong URL or Repo)    | Check owner/repo names and auth context               |\n| 422    | Validation Failed (Bad payload)  | Fix JSON body, ensure required fields present scopes  |\n| 500    | Server Error                     | Retry later (GitHub issue)                            |\n\n### Testing Errors with curl\n\n#### Invalid Token\n\n```bash\ncurl -H \"Authorization: token invalid_token\" https://api.github.com/user\n```\n\n#### Response:\n\n```json\n{\n  \"message\": \"Bad credentials\",\n  \"documentation_url\": \"https://docs.github.com/rest\"\n}\n```\n\n### Rate Limiting\n\nGitHub API uses two types of rate limits:\n\n- **Unauthenticated:** 60 requests/hour\n\n- **Authenticated:** 5000 requests/hour (with token)\n\nTo check your rate limit:\n\n```bash\ncurl -H \"Authorization: token YOUR_GITHUB_TOKEN\" \\\n     https://api.github.com/rate_limit\n```\n\n#### Response Example:\n\n```json\n{\n  \"rate\": {\n    \"limit\": 5000,\n    \"remaining\": 4998,\n    \"reset\": 1723782053\n  }\n}\n```\n\nTo convert `reset` UNIX timestamp:\n\n```bash\ndate -d @1723782053\n```\n\n### Error Tips in Postman\n\n- Use **Tests** tab to assert status codes:\n\n```js\npm.test(\"Status is 200\", () =\u003e {\n  pm.response.to.have.status(200);\n});\n```\n\n- Handle missing or invalid tokens:\n\n```js\nif (pm.response.code === 401) {\n  console.warn(\"Unauthorized – Check your token!\");\n}\n```\n\n## curl-scripts\n\nYou can run demo API calls via CLI by using the scripts in `/curl-scripts`.\n\n### Setup\nExport your token before running any script:\n\n```bash\nexport GITHUB_TOKEN=ghp_your_personal_access_token\n```\n\n| **Script**             | **Description**                |\n|------------------------|--------------------------------|\n| get-user.sh            | Get authenticated user info    |\n| list-repos.sh          | List all repos for user        |\n| create-repo.sh         | Create a new public repo       |\n| create-issue.sh        | Open an issue in a test repo   |\n| star-repo.sh           | Star a repo via curl           |\n\nRun with:\n\n```bash\n./curl-scripts/create-repo.sh test-repo\n```\n\n## LICENSE\n\nThis project is licensed under the [MIT License](./LICENSE).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthony-reese%2Fgithub-api-guide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanthony-reese%2Fgithub-api-guide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthony-reese%2Fgithub-api-guide/lists"}