Fix

Team abbreviation changes breaking sports data joins

Short answer: an abbreviation is a label, not a key. Teams move, rename and change codes, and the same code can name different teams in different sports. Join on a franchise key you control, keep the sport in it, and map season labels to that key with a small table.

The symptoms

Team join bugs hide in plausible output. A few signs to look for:

  • A team's history stops at a certain season, then a different team appears to start.
  • A join between a games table and a teams table loses all of one franchise's older games.
  • A team shows 82 games in a season and 0 in the one before it.
  • A cross-sport table has one "ATL" row that mixes a football score with a baseball one.
  • A request for one code returns games under a different code, and your check fails because the strings do not match.

All of these come from treating the abbreviation as an identity. It is a display value, and it changes.

Cause 1: one franchise, several codes over time

The clearest example is hockey. The franchise that played as the Phoenix Coyotes, then the Arizona Coyotes, then the Utah Hockey Club and now the Utah Mammoth has carried the NHL's codes PHX, ARI and UTA. The Atlanta Thrashers became the Winnipeg Jets in 2011, so the same franchise has used ATL and WPG.

In SportsDataHQ the hockey data is stored under one key per franchise, the current code. When you read a game, the label is chosen from the season so that history looks right. On December 6, 2026 we asked for UTA in three seasons. In 2013-14 the game came back labelled PHX, Phoenix Coyotes. In 2023-24 it came back labelled ARI, Arizona Coyotes. In 2025-26 it came back labelled UTA, Utah Mammoth, and in 2024-25 the same franchise was Utah Hockey Club. A request for WPG in 2010-11 came back labelled ATL, Atlanta Thrashers.

That design has two consequences. A query by the current code finds the whole history, so you never lose games to a rename. But the codes inside the rows are season labels, and list_teams returns only the 32 current codes. A join from game rows to the team list on homeTeam therefore fails for any old Coyotes or Thrashers game.

Cause 2: baseball keeps the current code

Baseball takes the other approach. The Athletics moved from Oakland to a new home, and the team list holds the current code, ATH, with a stable team_id. A game from October 1, 2023 carries ATH for the Athletics, with team id 11, and a request for OAK is accepted as an alias for the same team. So in baseball a join on the code works across the move, and the old label never appears in a row. This is easier on joins, but it means a historical table will show a code the team did not use at the time. If you publish a page for readers, add the period-correct name yourself.

The takeaway is that two APIs can handle the same kind of change in opposite ways. Read each one's rule instead of assuming.

Cause 3: one code, several sports

Codes are short, so the sports reuse them. We pulled the team lists from the hockey, football, basketball and baseball APIs and found 78 distinct codes, 29 of which belong to more than one sport. ATL is the Falcons, the Hawks and the Braves. DAL is the Stars, the Cowboys and the Mavericks. CHI names a team in three sports.

One city can also carry different codes. Washington is WAS in football and WSH in hockey, basketball and baseball. The Los Angeles football teams are LA for the Rams and LAC for the Chargers, and LAC is also the Clippers in basketball. Utah is UTA in hockey and UTAH in basketball. A key built on the code alone merges teams that have nothing to do with each other, and a key built on the city alone splits one team in two.

Several APIs accept the common alternates in requests. LAR resolves to LA in football, and WAS resolves to WSH in basketball. This is convenient, but the response uses the canonical code, so a join on what you sent will miss.

Step 1: see the shared codes

This script pulls the four team lists and reports how many codes are shared across sports. Set PUCKAPI_KEY, ENDZONEAPI_KEY, DUNKAPI_KEY and FASTBALLAPI_KEY, or load keys your own way. Each list costs 1 credit.

import json, os, urllib.request
from collections import defaultdict

def post(brand, tool, body):
    req = urllib.request.Request(f"https://mcp.{brand}.com/v1/{tool}", data=json.dumps(body).encode(),
                                 headers={"Content-Type": "application/json",
                                          "x-api-key": os.environ[brand.upper() + "_KEY"]})
    with urllib.request.urlopen(req, timeout=30) as resp:
        print("HTTP", resp.status, brand, tool)
        return json.load(resp)["data"]

codes = defaultdict(list)
for brand in ["puckapi", "endzoneapi", "dunkapi", "fastballapi"]:
    for t in post(brand, "list_teams", {})["teams"]:
        codes[t["abbrev"]].append((brand[:-3], t.get("name") or t.get("display_name")))

shared = {c: o for c, o in codes.items() if len(o) > 1}
print(len(codes), "distinct codes,", len(shared), "used by more than one sport")
print("ATL:", sorted(f"{b}: {n}" for b, n in codes["ATL"]))

On the verified run all four calls returned HTTP 200. The output was 78 distinct codes with 29 used by more than one sport, and ATL listed as the Hawks, the Falcons and the Braves.

Step 2: map season labels to the franchise key

For hockey, add a mapping from historical labels to the franchise's current code. The set that matters since the 2010-11 season is short: PHX and ARI map to UTA, and ATL maps to WPG. This script checks it against real games.

LABEL_TO_FRANCHISE = {"PHX": "UTA", "ARI": "UTA", "ATL": "WPG"}
current = {t["abbrev"] for t in post("puckapi", "list_teams", {})["teams"]}

for team, season in [("UTA", "20132014"), ("UTA", "20232024"), ("UTA", "20252026"),
                     ("WPG", "20102011"), ("WPG", "20252026")]:
    games = post("puckapi", "get_games", {"team": team, "season": season, "limit": 100})["games"]
    labels = {g[side] for g in games for side in ("homeTeam", "awayTeam")}
    missing = sorted(labels - current)
    fixed = sorted({LABEL_TO_FRANCHISE.get(c, c) for c in labels} - current)
    print(f"{team} {season}: {len(games)} games, labels not in list_teams: {missing}, after mapping: {fixed}")

On the verified run, 2013-14 returned PHX as a label missing from the team list, 2023-24 returned ARI, and 2010-11 for the Jets franchise returned ATL. The two 2025-26 checks returned no unmatched labels. After the mapping, every season came back with an empty list, so every game joined. Keep the table small and tested, because it is the only place where franchise history lives.

Step 3: key on franchise, sport and, where you can, the id

Build your own team table with a surrogate key, the sport, the API's current code, and the API's team_id where one exists. Baseball, basketball and soccer rows carry a team_id, and that is a safer join than the code. Hockey does not return a team id in the team list, so the franchise code plus the mapping above is the key. Store the label as it appeared on each game as a display column, never as the key.

Step 4: test on the seasons that changed

Pick one season on each side of every known change and assert that your team-level counts are continuous. A franchise that plays 82 games every year should not drop to zero in a year with a new label. Run the check when you add a league, because the first time a team renames, your table will show it.

When not to use this

  • You need a legal or historical name for display. The label follows the season for hockey, but baseball and others return the current name. Keep your own table of period names for editorial use.
  • You need teams in leagues with their own code space. A junior or minor league has its own teams, and its WPG is not the NHL's franchise. Keep the league in the key.
  • You only look at the current season. A single current season has one code per team, and the mapping is not needed.

Get a free key

Checked against the live API on 2026-12-06. Questions: hello@sportsdatahq.com.