Glassdoor Salary Data API in Python: Compare Employer Pay to a City Baseline
Maya is closing a software-engineer req in San Francisco. The hiring manager will not click through employer pages. What they will open is a spreadsheet: Google, Meta, Netflix in the first column, each employer's min / median / max for that title in that city, and one extra set of columns for the city-wide baseline so an offer is not priced in a vacuum. She does not need reviews, interview questions, or every role on a career site. She needs one file.
The Glassdoor Employer Data API is an unofficial data service, not an affiliated Glassdoor product. It returns publicly available, employee-reported figures as JSON at request time; that is not a guarantee of current pay. Copying a snippet from this page does not send a lookup — only a request you actually run does.
Sign in, copy a key from the dashboard, and keep it in OPENDATA_API_KEY on the server. Snippets that show YOUR_API_KEY are placeholders. The key travels in the query string, so those URLs do not belong in tickets, screenshots, or browser JavaScript.
The comparison a recruiter actually exports
The artifact is compensation-comparison.csv. One row per shortlisted employer. Shared on every row: the title, the city, and the market baseline from salary-estimate. Employer-specific columns: the company_id you resolved, the name Glassdoor returned, min / median / max total pay from company-salaries, currency, pay period, salary_count, and confidence.
That is three operations, not a catalog. company-search turns a typed name into a stable company_id. company-salaries needs that id plus job_title. salary-estimate needs job_title and location and no employer at all. company-salaries-v2 pages every reported role at one company — a different export. Leave it out of this file.
Keep the title, city, and optional years_of_experience band identical across every call. Mixing a national employer range with a city market figure is how a "below market" slide gets built on mismatched geography. If you pass FOUR_TO_SIX on one side, pass it on the other.
Resolve names to company_id once
Every company-scoped call keys off a numeric company_id, not the string you type. Search once per name, store the id, and reuse it. Re-searching the same shortlist on every run burns credits and invites a different top hit.
Transport is the first layer: HTTP 4xx / 5xx means the call did not run (auth, quota, or network). The gateway envelope is {code, message, data}. code 200 means the platform accepted the request. It does not mean a company was found. A search with no matches returns an empty data array — stop that name; do not retry the same query in a loop.
def resolve_company_id(name, cache):
if name in cache:
return cache[name]
hits = call("company-search", query=name, limit=5) or []
chosen = None
for hit in hits:
if str(hit.get("name", "")).lower() == name.lower():
chosen = hit
break
if chosen is None and hits:
chosen = hits[0] # ranked fallback; store the name you actually got
cache[name] = chosen
return chosen
A search for google is the documented example; the first hit is commonly company id 9079. Prefer an exact name match when several brands share a stem, and write the returned name into the CSV so a fallback is visible. Hits also carry rating, salary_count, and headquarters_location — useful for a sanity column, not a second salary call.
Employer range next to the city baseline
company-salaries is one estimate for one role at one employer. Required: company_id and job_title. For this CSV, also send location=san francisco and location_type=CITY so the employer row shares a geography with the market row.
The data object, when present, is a single estimate: min_salary, median_salary, and max_salary for total pay; separate *_base_salary and *_additional_pay splits; salary_period (for example YEAR); salary_currency; salary_count of employee reports; and a confidence label. Put totals in the spreadsheet. Do not compare one employer's base pay to another employer's total package. Read salary_count and confidence before anyone quotes a median in a hiring meeting — a wide band backed by thousands of reports is not the same object as a tight band backed by three.
Unknown company_id is the quiet miss: HTTP 200, gateway code 200, and no data field. That is "not found", not a retryable outage. Skip the row.
salary-estimate is the yardstick. It needs no company. Pass the same job_title, location, and location_type. Call it once for the city and copy the range onto every employer row. If data is missing, leave the market columns empty — do not invent a baseline. Align salary_period and salary_currency before you subtract medians; an hourly figure next to an annual one is not a premium.
Optional years_of_experience bands (LESS_THAN_ONE through ABOVE_FIFTEEN) tighten both calls the same way. domain switches the regional Glassdoor site when the market is not the default United States site — keep that flag consistent too.
The script that writes the CSV
Install requests, export OPENDATA_API_KEY, and run this as a server-side job. It resolves each name once, pulls one employer estimate per shortlist entry, fetches the city baseline once, and writes compensation-comparison.csv. Missing fields stay missing. An empty shortlist writes nothing.
import csv
import os
import time
import requests
BASE = "https://api.opendata-api.com/api/project/glassdoor"
KEY = os.environ["OPENDATA_API_KEY"].strip()
JOB_TITLE = "software engineer"
LOCATION = "san francisco"
COMPANIES = ["google", "meta", "netflix"]
OUT = "compensation-comparison.csv"
def call(operation, **params):
resp = requests.get(
f"{BASE}/{operation}",
params={"key": KEY, **params},
timeout=30,
)
resp.raise_for_status() # HTTP layer: 4xx/5xx is transport or quota
envelope = resp.json()
if str(envelope.get("code")) != "200":
raise RuntimeError(envelope.get("message"))
return envelope.get("data") # may be missing, empty, or a payload
def resolve_company_id(name, cache):
if name in cache:
return cache[name]
hits = call("company-search", query=name, limit=5) or []
chosen = None
for hit in hits:
if str(hit.get("name", "")).lower() == name.lower():
chosen = hit
break
if chosen is None and hits:
chosen = hits[0]
cache[name] = chosen
return chosen
def main():
cache = {}
market = call(
"salary-estimate",
job_title=JOB_TITLE,
location=LOCATION,
location_type="CITY",
) or {}
rows = []
for name in COMPANIES:
hit = resolve_company_id(name, cache)
if not hit or hit.get("company_id") is None:
continue # empty search: skip, do not retry
company_id = str(hit.get("company_id"))
estimate = call(
"company-salaries",
company_id=company_id,
job_title=JOB_TITLE,
location=LOCATION,
location_type="CITY",
)
if not estimate:
# Unknown id: HTTP 200, gateway code 200, no data field
continue
rows.append({
"company": hit.get("name", name),
"company_id": company_id,
"rating": hit.get("rating"),
"job_title": JOB_TITLE,
"location": LOCATION,
"min_total": estimate.get("min_salary"),
"median_total": estimate.get("median_salary"),
"max_total": estimate.get("max_salary"),
"currency": estimate.get("salary_currency"),
"period": estimate.get("salary_period"),
"reports": estimate.get("salary_count"),
"confidence": estimate.get("confidence"),
"market_min": market.get("min_salary"),
"market_median": market.get("median_salary"),
"market_max": market.get("max_salary"),
"market_currency": market.get("salary_currency"),
"market_period": market.get("salary_period"),
})
time.sleep(1)
if not rows:
raise SystemExit("No employer rows to write")
with open(OUT, "w", newline="") as handle:
writer = csv.DictWriter(handle, fieldnames=list(rows[0].keys()))
writer.writeheader()
writer.writerows(rows)
if __name__ == "__main__":
main()
That file is the whole deliverable: named employers next to one city baseline, for one title. Parameter notes live on company search, company salaries, and salary estimate.