Short Answer
You need to use the "List stargazers" REST API and add the header "Accept: application/vnd.github.star+json
" to the request.
curl -L -s \ -H "Accept: application/vnd.github.star+json" \ https://api.github.com/repos/{owner}/{repo}/stargazers
Docs Reference
From GitHub Docs: REST APIs - List stargazers
Lists the people that have starred the repository.
This endpoint supports the following custom media types. For more information, see "Media types."
application/vnd.github.star+json
: Includes a timestamp of when the star was created.
Example (Single Page)
Here's a quick example without an access token:
curl -L -s \ -H "Accept: application/vnd.github.star+json" \ https://api.github.com/repos/mikyll/SDL2-Controller-Tester/stargazers
This command retrieves the stars (up to 100) of the first page of the repository mikyll/SDL2-Controller-Tester.
If you hit the GitHub API rate limit, you can add a personal access token to the request with the authorization header (-H "Authorization: token <gh_token>"
).
To manage access tokens you can access this page.
Example (Multiple Pages)
List stargazers API retrieves stars based on their page number, and you can use query parameters to customize that:
page
sets the page number of the results to fetch (default 1);per_page
sets the number of results per page (max 100);
When addressing repositories with a high number of stars, to get the full star history you have to send multiple requests.
The following Bash script loops over all the pages (each valid response contains a header with the link to the next page) and saves a simpler JSON in a file star_history.json
:
#!/bin/bash# GitHub repository detailsOWNER="owner_name"REPO="repository_name"# GitHub personal access token for authentication (it provides higher rate limit)TOKEN="github_token"# Base URL for the GitHub APIURL="https://api.github.com/repos/${OWNER}/${REPO}/stargazers"# Custom accept header to include starred_at timestampACCEPT_HEADER="Accept: application/vnd.github.star+json"# Authentication header (uncomment if using a token)# AUTH_HEADER="Authorization: token ${TOKEN}"# Initial pagePAGE=1# Max results per pagePER_PAGE=100# Loop through all pages of resultswhile truedo # Make request to GitHub API RESPONSE=$(curl -s -H "${ACCEPT_HEADER}" -H "${AUTH_HEADER}" "${URL}?page=${PAGE}&per_page=${PER_PAGE}") # Check if the response is empty if [ -z "${RESPONSE}" ] || [ "${RESPONSE}" == "[]" ] || [[ "${RESPONSE}" != *"starred_at"* ]] then break fi # Check if rate limit was hit if [[ "${RESPONSE}" == *"API rate limit exceeded"* ]] then break else # Process the response echo "${RESPONSE}" # Increment the page number ((PAGE++)) fidone | jq '[ .[] | { "username": .user.login, "timestamp": .starred_at } ]'> star_history.json