How to get a GitHub user's contribution graph as JSON, without a token
By Hayden Barnett · · 5 min read
- GitHub
- Contributions
- Python
The green grid on a GitHub profile is the contribution calendar: one square per day, shaded by how much that account did. GitHub’s REST API has no endpoint for it. The documented route is the GraphQL API, through contributionsCollection, which needs a bearer token and a query that walks weeks of days.
If all you want is the calendar, one GET returns it as JSON:
export FETCHPROOF_API_KEY=fp_live_xxx
curl -s "https://api.fetchproof.com/v1/github/user/contributions?handle=torvalds&year=2025" \
--header "x-api-key: $FETCHPROOF_API_KEY"
Pass handle (the username) or url (the profile URL). year is optional and defaults to the current year. The body is a flat list of days, oldest first, each with its date, its contribution count and its shade, plus the year’s total as GitHub prints it. There is no GitHub token and no GraphQL. The credential is the Fetchproof key in x-api-key.
Why the usual routes are more work than the grid
The top results for this query are GraphQL tutorials, and they work. Each one costs more setup than a heatmap is worth.
GraphQL needs a token. Every GraphQL call to api.github.com/graphql is authenticated. For a portfolio site, a README badge or a dashboard that shows other people’s grids, that means a personal access token stored somewhere your build or server can read it, with its own expiry to track.
The shape is nested. The calendar comes back as weeks, each holding contributionDays. Most charts want one row per day, so the first thing every tutorial does is flatten the weeks. The response here is already flat.
Scraping the profile yourself. The grid is HTML. Each square is a table cell with a data-date and a data-level, and the count lives in a separate tooltip element linked by id. That markup belongs to the website, and it changes. A scheduled job that parses it on a cloud IP also has to handle GitHub refusing the request. Fetchproof treats a refused or failed upstream read as an error response, never as a calendar full of zeros.
What comes back
Field names and types below match the published schema for the contributions endpoint. The counts are placeholders, so the sample does not describe anyone’s real year.
{
"success": true,
"credits_remaining": 99,
"credits_charged": 1,
"contributions": {
"username": "torvalds",
"year": 2025,
"total_contributions": 1200,
"days": [
{ "date": "2025-01-01", "contribution_count": 4, "color": null, "intensity": 1 },
{ "date": "2025-01-02", "contribution_count": 16, "color": null, "intensity": 2 },
{ "date": "2025-01-03", "contribution_count": 0, "color": null, "intensity": 0 }
]
}
}
days has one entry per square, sorted by date (YYYY-MM-DD). Days without activity are in the list with contribution_count 0, so a chart never has gaps to fill. intensity is GitHub’s own shade level, 0 for an empty square up to 4 for its busiest. Use it when you want your heatmap to match the profile. color is null. Pick your own palette from intensity.
total_contributions is the total GitHub prints above the grid (“N contributions in 2025”). Prefer it over summing days when you display a headline number.
For the current year, the grid runs January 1 to December 31, so the days after today are listed with a count of 0. Filter on date if you are computing an average or a streak.
The counts are what the public profile shows. Contributions to private repositories are included only when the account owner has turned on private contributions in their profile settings.
Python
The standard library is enough. Keep the key in the environment. The samples on this page use the placeholder fp_live_xxx.
import json
import os
import urllib.parse
import urllib.request
from datetime import date
query = urllib.parse.urlencode({"handle": "torvalds", "year": 2025})
request = urllib.request.Request(
"https://api.fetchproof.com/v1/github/user/contributions?" + query,
headers={"x-api-key": os.environ["FETCHPROOF_API_KEY"]},
)
with urllib.request.urlopen(request, timeout=60) as response:
body = json.load(response)
calendar = body["contributions"]
today = date.today().isoformat()
days = [d for d in calendar["days"] if d["date"] <= today]
longest = current = 0
for day in days:
current = current + 1 if day["contribution_count"] > 0 else 0
longest = max(longest, current)
active = sum(1 for d in days if d["contribution_count"] > 0)
print(f"{calendar['username']} {calendar['year']}: {calendar['total_contributions']} contributions")
print(f"active days: {active}, longest streak: {longest} days")
urlopen raises on an error status, which covers a bad year or an account that does not exist. The date <= today filter keeps the empty future squares of the current year out of the streak and the active-day count.
Node
Node 18 and later include fetch. This version writes one CSV row per day, ready for a spreadsheet or a charting library:
import { writeFileSync } from "node:fs";
const url = new URL("https://api.fetchproof.com/v1/github/user/contributions");
url.searchParams.set("url", "https://github.com/torvalds");
url.searchParams.set("year", "2025");
const response = await fetch(url, {
headers: { "x-api-key": process.env.FETCHPROOF_API_KEY },
});
if (!response.ok) {
throw new Error(`GitHub contributions failed: HTTP ${response.status}`);
}
const { contributions } = await response.json();
const rows = contributions.days.map((d) => `${d.date},${d.contribution_count},${d.intensity}`);
writeFileSync("contributions.csv", ["date,count,level", ...rows].join("\n"));
console.log(contributions.username, contributions.total_contributions, "contributions in", contributions.year);
This call passes the profile url instead of handle. Either works, and you only need one.
Every year since an account started
One call is one calendar year. For a lifetime chart, loop over years. year accepts 2008, the year GitHub launched, through the current year:
for year in 2023 2024 2025; do
curl -s "https://api.fetchproof.com/v1/github/user/contributions?handle=torvalds&year=$year" \
--header "x-api-key: $FETCHPROOF_API_KEY" > "torvalds-$year.json"
done
Start at the year the account was created. The user endpoint returns GitHub’s user object, which includes created_at, so you can skip the years before it instead of paying for them:
curl -s "https://api.fetchproof.com/v1/github/user?handle=torvalds" \
--header "x-api-key: $FETCHPROOF_API_KEY"
A year outside that range, such as year=2007 or next year, never reaches GitHub. It is HTTP 400 with error set to invalid_parameter.
The calendar gives counts, not what the work was. For the commits, pull requests and issues behind a month of squares, the activity endpoint returns the profile’s “Contribution activity” timeline.
From n8n or an MCP client
The same x-api-key header is what the n8n HTTP Request post configures once. Point that node at /v1/github/user/contributions and send handle and year as query parameters. From an MCP client, the tool name is github_user_contributions. Setup for the server is in the MCP docs. If you also track what is rising on GitHub, the trending repositories tutorial uses the same key.
What a call costs
The contributions call costs 1 credit by default, for one year of one account. A three-year loop plus one user lookup is 4 credits if each one returns data. Errors, blocked or timed-out requests, invalid requests and cache hits cost nothing. A not-found or empty result is charged only where that operation’s published cost says so.
This operation publishes that default and no separate empty or not-found price. A year with no activity is still HTTP 200 with success: true and a full list of zero days. Read credits_charged on the body. The contributions endpoint page states the published cost.
New accounts get 100 free credits, with no card. Pack sizes and prices are on the pricing page. How a prepaid pack compares with a monthly quota that resets is in prepaid credits vs monthly subscriptions. Every GitHub route sits on the GitHub API page.
FAQ
Does GitHub have an API for the contribution graph?
Only through GraphQL, as of Dec 2026. The contributionsCollection field on a user returns a contributionCalendar grouped by weeks, and every GraphQL call needs a token. The REST API has no contribution calendar resource. This endpoint reads the public profile’s calendar and returns it as flat JSON.
Can I get the last 12 months instead of a calendar year?
Not in one call. The endpoint takes a calendar year. For a rolling twelve months, request this year and last year, then keep the days whose date falls in your window.
Why is color always null?
color is in the published schema, and this endpoint always returns it as null. The shade is carried by intensity, GitHub’s 0-4 level. Map those five levels to your own colors. That also keeps your chart readable in dark mode.
Does it include private contributions?
Only when the account shows them. GitHub counts private contributions on the public profile when the owner enables that setting, and the calendar here is what the public profile shows. Without the setting, private work is not in the counts.
Related guides and endpoints
Try it with 100 free credits
Sign up with an email address, no card. Credits never expire. Errors, invalid requests and cache hits cost 0 credits, and each endpoint page lists exactly what it charges.