[!TIP]

[!NOTE|label:headers]

  • -H "Accept: application/vnd.github.v3+json"
  • -H "Authorization: token <TOKEN>"
  • -H "Authorization: Bearer <TOKEN>"
  • -H "Content-Type: application/json"
  • -H "Time-Zone: Europe/Amsterdam"
  • -H "X-GitHub-Api-Version: 2022-11-28"

user

get username from token

$ curl -s -H "Authorization: token <TOKEN>" https://api.github.com/user | jq -r .login
# or
$ curl -s -H "Authorization: Bearer <TOKEN>" https://api.github.com/user | jq -r .login

metadata

$ curl -sL https://api.github.com/meta | jq -r '.ssh_keys | .[]'
$ curl -sL https://api.github.com/meta | jq -r '.ssh_keys | .[]'  | sed -e 's/^/github.com /' >> ~/.ssh/know_hosts

repo

  • list all repos and permissions

    [!TIP]

    • list all repos: GET /user/repos
    • list repos in special /: GET /orgs/<ORG>/repos
    $ curl -sS -g -H "Authorization: Bearer <TOKEN>" \
           -H "Accept: application/vnd.github+json"
           'https://api.github.com/user/repos?per_page=100&type=all' |
      jq -r '.[] | select(.permissions != null)
                 | (
                     if   p.admin     then "ADMIN"
                     elif p.maintain  then "MAINTAIN"
                     elif p.push      then "WRITE"
                     elif p.triage    then "TRIAGE"
                     elif p.pull      then "READ"
                     else "NONE" end
                   )
                   + "\t" + .html_url' |
      sort
    
  • get repo info

    [!TIP] GET /repos/{owner}/{repo}

    # i.e.:
    $ curl -fsSL https://api.github.com/repos/marslo/ibook
    
  • get repo contributors

    [!TIP] GET /repos/{owner}/{repo}/contributors

    # i.e.:
    $ curl -fsSL https://api.github.com/repos/marslo/ibook/contributors
    
  • disable actions workflow

    # disable
    $ gh api -X PUT "repos/${ORG}/${REPO}/actions/permissions" -F enabled=false
    
    # check status
    $ gh api "repos/${ORG}/${REPO}/actions/permissions" --jq '.enabled'
    

pull request

  • get pull request info

    [!TIP] GET /repos/{owner}/{repo}/pulls/{pull_number}

    # i.e.:
    $ curl -fsSL https://api.github.com/repos/marslo/ibook/pulls/1
    
  • get comments of a pull request

    [!TIP] GET /repos/{owner}/{repo}/issues/{issue_number}/comments

    # i.e.:
    $ curl -fsSL https://api.github.com/repos/marslo/ibook/issues/1/comments
    

branches

get branches

[!TIP] GET /repos/{owner}/{repo}/branches

# i.e.:
$ curl -fsSL https://api.github.com/repos/marslo/ibook/branches

get details of a branch

[!TIP] GET /repos/{owner}/{repo}/branches/{branch}

# i.e.:
$ curl -fsSL https://api.github.com/repos/marslo/ibook/branches/main

revision and tags

get commits

[!TIP|label:API] GET /repos/{owner}/{repo}/commits

$ curl -fsSL https://api.github.com/repos/<OWNER>/<REPO>/commits

# i.e.:
$ curl -fsSL https://api.github.com/repos/marslo/ibook/commits

post commit status

[!TIP|label:API] POST repos/${OWNER}/${REPO}/statuses/${sha}

$ curl -X POST -H "Authorization: token ${GITHUB_TOKEN}" \
       -H "Accept: application/vnd.github+json" \
       https://api.github.com/repos/${OWNER}/${REPO}/statuses/${SHA} \
       -d '{
         "state": "success",
         "target_url": "https://ci.example.com/build/status/123",
         "description": "All tests passed",
         "context": "ci/build"
       }'

get HEAD of branch

[!TIP|label:API] GET /repos/{owner}/{repo}/git/refs/heads/{branch}

$ curl -fsSL https://api.github.com/repos/<OWNER>/<REPO>/git/refs/heads/<BRANCH>
# i.e.:
$ curl -fsSL https://api.github.com/repos/marslo/ibook/git/refs/heads/marslo --jq .object.sha

$ gh api "repos/<OWNER>/<REPO>/refs/heads/<BRANCH>"
# i.e.:
$ gh api "repos/marslo/ibook/git/refs/heads/marslo" --jq .object.sha

get revision info

[!TIP|label:API] GET /repos/{owner}/{repo}/commits/{sha}

$ gh api repos/{owner}/${REPO}/commits/${sha}

# i.e.:
$ gh api repos/${OWNER}/${REPO}/commits/${sha} \
     --jq '[
            "revision: \(.sha)",
            "author: \(.commit.author.name) <\(.commit.author.email)> - \(.commit.author.date)",
            "committer: \(.commit.committer.name) <\(.commit.committer.email)> - \(.commit.committer.date)",
            {message: (.commit.message | split("\n")) }
           ]'

actions runners

  • list workflow runs

    [!TIP|label:API] GET /repos/{owner}/{repo}/actions/runs

    $ curl -fsSL https://api.github.com/repos/<OWNER>/<REPO>/actions/runs
    
    # i.e.:
    $ curl -fsSL https://api.github.com/repos/marslo/ibook/actions/runs
    
  • get workflow run logs

    [!TIP|label:API] GET /repos/{owner}/{repo}/actions/runs/{run_id}/logs

    $ curl -fsSL https://api.github.com/repos/<OWNER>/<REPO>/actions/runs/<RUN_ID>/logs
    
    # i.e.:
    $ curl -fsSL https://api.github.com/repos/marslo/ibook/actions/runs/1234567890/logs
    
  • trigger workflow run

    [!TIP|label:API] POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches

    # i.e.:
    $ curl -X POST -H "Accept: application/vnd.github.v3+json" \
      -H "Authorization: token ghp_v**********************************n" \
      https://api.github.com/repos/marslo/ibook/actions/workflows/ci.yml/dispatches \
      -d '{"ref":"main"}'
    

releases

release version

$ curl --silent 'https://api.github.com/repos/<owner>/<repo>/releases/latest' | jq -r .tag_name

# i.e.:
$ curl --silent 'https://api.github.com/repos/sharkdp/bat/releases/latest' | jq -r .tag_name

have fun

emoji

$ curl -fsSL -XGET https://api.github.com/emojis

zen

$ curl -fsSL -XGET https://api.github.com/zen

octocat

$ curl -fsSL -XGET https://api.github.com/octocat

rate limit

$ curl -fsSL -XGET https://api.github.com/rate_limit
Copyright © marslo 2020-2026 all right reserved,powered by GitbookLast Modified: 2026-08-27 05:21:41

results matching ""

    No results matching ""