Building a school picker
GET /v1/schools/autocomplete suggests institutions from a fragment of a name. It is the one endpoint a publishable key reaches and the one a browser can call directly. It doesn’t count against your monthly allowance on any tier.
1. Create a publishable key
Section titled “1. Create a publishable key”In the developer console, create a publishable key and register the origins your page is served from, such as https://app.example.com. A request carrying the key from any other origin, or with no Origin header, is refused. So you can’t test a publishable key with curl or from a server.
Never put a secret key in a page. The other /v1 endpoints send no CORS headers, so a browser can’t call them.
2. Send the fragment
Section titled “2. Send the fragment”GET /v1/schools/autocomplete?q=harvard&state=MA&limit=10x-api-key: pk_live_...| Parameter | Takes |
|---|---|
q |
The text typed so far, up to 100 characters. It ranks from two characters, counted after punctuation is removed. |
limit |
1 to 20 suggestions. Defaults to 10. |
state, control, level, closed, titleIv |
The same filters as GET /v1/schools. See Making requests. |
A request needs a q that ranks or at least one filter, and answers 422 with neither. With q, suggestions are ranked by match. With filters alone, they come most recently changed first. Either way the answer is one page.
A publishable key filters as Startup at most, whatever your plan. The suggestions themselves are the same at every tier.
3. Render the suggestions
Section titled “3. Render the suggestions”{ "success": true, "data": { "schools": [ { "id": "019fd39c-0187-7a2e-b4c1-6f0d2e8a9b13", "name": "Harvard University", "city": "Cambridge", "state": "MA", "address": "Massachusetts Hall", "phone": "+16174951000", "phoneExtension": null, "website": "https://www.harvard.edu/", "logoUrl": null, "faviconUrl": null, "unitid": "166027", "matchedName": "Harvard University", "matchedType": "official", "score": 1 } ] }, "meta": { "requestId": "01K2...", "timestamp": "..." }}- Show
name,city, andstateso people can tell campuses apart. - Show
matchedTypewhen it isn’tofficial. If someone typed an acronym or a former name, say so beside the result.matchedNameandscorearenullon those results, as Matching and scores explains. - Treat a
nulllogoUrlorfaviconUrlas no image and show a placeholder. Do the same when the image fails to load. A school can have one, both, or neither. - Order by the response, not by
score. The list is already ranked. - Expect
matchedName,matchedType, andscoreallnullon a request with filters and noq. Nothing was matched by name.
address, phone, and website let you show where a school is without a second request. Each is null where the institution published nothing.
4. Store id
Section titled “4. Store id”When someone picks a school, store its id. Every institution has one. unitid is null for institutions with no IPEDS record, so it can’t be your key. Fetch the full record by id when you need it, with a secret key on your server.
Limits to design around
Section titled “Limits to design around”- Debounce. Every keystroke can be a request. The rate limit applies per key and, for a publishable key, also per visitor address. Rate limits and quotas has the numbers.
- A
429from the per-address limit carries noRetry-After. Wait a second or two and try again. - A
503means the search index hasn’t loaded yet. It carriesRetry-After. Show the field as unavailable rather than as “no results”. - A common word matches too much.
universityalone returns ten arbitrary universities. Suggest typing more of the name.
autocompleteSchools has the full schema.