cURL with GitHub

GET profile details

curl -i -u <USERNAME> https://api.github.com/users/<USERNAME>
curl -i https://api.github.com/users/octocat

-u flag sets the username, and cURL will prompt you for the password. -i flag to includes headers in the response.

curl -i -u <USERNAME> https://api.github.com/user
curl -u "octocat" https://api.github.com

Use Basic Authentication towards an authorization endpoint in the Authorizations API to fetch an OAuth token (40 characters). An optional array of scopes, or access levels, indicates what information the token can access.

curl -i -u <USERNAME> \
  -d '{"scopes": ["repo", "user", "delete_repo"], "note": "<NOTE>"}' https://api.github.com/authorizations

List all authorizations

curl -X GET https://api.github.com/authorizations -u <USERNAME>

Get a single authorization

curl -X GET https://api.github.com/authorizations/<AUTHORIZATION_ID> -u <USERNAME>

Delete a single authorization (probably no longer in use)

curl -X DELETE https://api.github.com/authorizations/<AUTHORIZATION_ID> -u <USERNAME>

Update a single authorization

curl -X PATCH https://api.github.com/authorizations/<AUTHORIZATION_ID> -u <USERNAME> \
  -d  "{\"note\":\"<NOTE>\",\"fingerprint\":\"<FINGERPRINT>\"}"

Similarly, it is possible to list all application grants, get a single grant, or delete a grant

curl -X GET https://api.github.com/applications/grants -u <USERNAME>
curl -X GET https://api.github.com/applications/grants/<GRANT_ID> -u <USERNAME>
curl -X DELETE https://api.github.com/applications/grants/<GRANT_ID> -u <USERNAME>

Use Access Token as a password to make authorized calls to the Github API. The tokens act as credentials used to access protected resources. It is a string representing an authorization issued to the client.

curl -i https://api.github.com/user \
  -H "Authorization: token <TOKEN>"

List all public projects associated with an organization

curl -X GET https://api.github.com/orgs/octokit/projects \
  -H "Accept: application/vnd.github.inertia-preview+json"

Create a Github project

curl -X POST https://api.github.com/user/projects \
  -H "Authorization: token <TOKEN>" \
  -H "Accept: application/vnd.github.inertia-preview+json" \
  -d  "{\"name\":\"k-quotes\",\"body\":\"Wisdom Quotes\"}"

Delete a Github project

curl -X DELETE https://api.github.com/projects/<PROJECT_ID> \
  -H "Accept: application/vnd.github.inertia-preview+json" \
  -H "Authorization: token <TOKEN>"

List of all public repositories in an organization

curl -X GET https://api.github.com/orgs/octokit/repos

curl -i https://api.github.com/orgs/mozilla/repos
curl -i https://api.github.com/orgs/mozilla/repos?sort="full_name"&type="owner"&direction="asc"

List all repositories of a user

curl -i -H "Authorization: token <TOKEN>" \
    https://api.github.com/<USERNAME>/repos

curl -i https://api.github.com/users/<USERNAME>/repos

Create a repository

curl -i -H "Authorization: token <TOKEN>" \
    -d '{ \
        "name": "sample-repo", \
        "auto_init": true, \
        "private": true, \
        "gitignore_template": "nanoc" \
      }' \
    https://api.github.com/user/repos

List all issues

curl -i -H "Authorization: token <TOKEN>" https://api.github.com/issues

Links