# Crossword Grid Search API > A free JSON API for searching 162,749 published crossword grids (black-square layouts) from 175 outlets, the New York Times among them: find the layouts that hold a set of theme entries, or search by pattern, shape, size, outlet, day of the week and word lengths. No key, no sign-up, GET only. - Base URL: https://ugleh.com/gridsearch/api/v1 - These docs as a web page: https://ugleh.com/gridsearch/api/ - The search page, where people draw a grid and search: https://ugleh.com/gridsearch/ - Version 1. It may gain endpoints, parameters and fields (ignore fields you do not know); a change that would break a working program goes to /v2/ instead. ## Essentials - Most people want grids for a theme: "which 15x15 layouts hold two 15s and two 11s across?" That is GET /themes, the next section. - Every endpoint is GET, with parameters in the query string. Answers are JSON (UTF-8). CORS allows any origin. - A grid is one string, row by row from the top left: `.` is a black square, `-` a white square. In a pattern you send, `_` is a square that can be either. A 15x15 grid is 225 characters. To get rows, cut it every `width` characters. - GridSearch has grids only: no answers, clues or titles. - Pictures only on request (`image=svg`, or `/grids/{id}.svg`); an SVG is about 46 times larger than the grid's text. - Optional: a grid can also be written as a short grid code (see "Grid codes (optional)"), in requests (`code=`) and in answers (`grid_format=code`). You never need codes; width, height and pattern do everything. - A parameter an endpoint does not know is an error (400), so a misspelt filter never silently matches everything. - Please send a User-Agent naming your program and how to reach you, accept gzip, fetch 100 results a page with cursors, and do not use the API to copy the whole collection. ## GET /themes Grids for a theme, the question constructors ask most. Give the grid size and the theme entries' (themers') lengths; get every published layout that can hold them, most used first, each with one placement of the themers and its newest puzzles. A layout is one arrangement of black squares, counted once however it was turned or flipped. Parameters: - `width`, `height`: required (unless `code`). The grid's size. A layout published the other way round is turned on its side to fit. - `themers`: required. Up to 12 theme entries, comma-separated. Each is a length (3 or more), optionally followed by `a`/`across` or `d`/`down` (no direction: either), optionally followed by `@r{row}c{col}` for the square it starts on (counted from 1 at the top left). Case does not matter. Examples: `15` (15 letters, across or down), `15a` (across), `9d` (down), `15a@r3c1` (across from row 3, column 1), `9@r1c4` (either way from row 1, column 4). - `pattern`, `code`: squares the layout must have, as for /search. - `outlet`, `days`, `blocks`, `words`, `words_N`, `symmetry`: the filters of /search. A layout counts only the puzzles that pass them. - `limit`, `cursor`, `image`, `grid_format`: as for /search. Not `grid_width` or `grid_height`. A themer needs an entry of exactly its length (black square or edge at both ends), and two themers never share an entry. Answer: - `themers`: the themers as read: `length`, `direction` (`across`, `down` or `any`), and `row` and `col` when a start was given. - `counts` (on every page): `layouts` (layouts that fit), `puzzles` (puzzles that use them), `complete` (false when the themers fit nearly every grid, such as a lone short entry, and only the 20,000 most used layouts were looked at). - `results`: the page of layouts, most used first. Each has `width`, `height`, `grid` (or `code`; turned to the size asked for and so the themers fit, as published when possible), `blocks`, `words`, `symmetry` (list), `puzzles` (published puzzles using this layout), `themers` (where each themer goes, in the order given: `length`, `direction`, `row`, `col` of the first letter, from 1), `examples` (up to three of its puzzles, newest first: `id`, `xdid`, `outlet`, `date`, `transform`, `link`; `transform` says how that puzzle as published turns into the layout shown), and `svg` if asked for. - `next_cursor`: send as `cursor` for the next page; null on the last. Pages go by position; each page runs the search again, so take 100 at a time. The placement is one way the themers fit; a layout may have others, and it is not a claim about which entries the original puzzles used as their theme. There are no letters, so words are not checked. One or two long themers answer in well under a second; themers nearly every grid holds can take a couple of seconds. Example: 15x15 layouts for two 15s and two 11s across (1,246 layouts, 253 of them in the New York Times with `outlet=nyt`), the most used: ``` curl -G --compressed https://ugleh.com/gridsearch/api/v1/themes -d width=15 -d height=15 -d themers=15a,15a,11a,11a -d limit=1 ``` ```json { "themers": [ { "length": 15, "direction": "across" }, { "length": 15, "direction": "across" }, { "length": 11, "direction": "across" }, { "length": 11, "direction": "across" } ], "counts": { "layouts": 1246, "puzzles": 1477, "complete": true }, "results": [ { "width": 15, "height": 15, "grid": "-----.----.---------.----.----------------------.----.------...----.----...-----------.--------..---.--------.-----.--------.---..--------.-----------...----.----...------.----.----------------------.----.---------.----.-----", "blocks": 36, "words": 78, "symmetry": ["rot180"], "puzzles": 39, "themers": [ { "length": 15, "direction": "across", "row": 3, "col": 1 }, { "length": 15, "direction": "across", "row": 13, "col": 1 }, { "length": 11, "direction": "across", "row": 6, "col": 1 }, { "length": 11, "direction": "across", "row": 10, "col": 5 } ], "examples": [ { "id": 160288, "xdid": "cdsun2026-09-23", "outlet": "The Cornell Daily Sun", "date": "2026-09-23", "transform": "none", "link": "https://crosswordreference.com/puzzle/xd/cdsun2026-09-23" }, { "id": 151733, "xdid": "tfts2026-01-20", "outlet": "The Tufts Daily", "date": "2026-01-20", "transform": "none", "link": "https://crosswordreference.com/puzzle/xd/tfts2026-01-20" }, { "id": 150082, "xdid": "uva2025-11-30", "outlet": "The Cavalier Daily", "date": "2025-11-30", "transform": "none", "link": "https://crosswordreference.com/puzzle/xd/uva2025-11-30" } ] } ], "next_cursor": "dDE" } ``` With starts: `themers=15a@r3c1,15a@r13c1,9d@r1c4` finds 405 layouts with 15s across rows 3 and 13 and a 9 down from the top of column 4. In Python, the top five layouts with the themers' squares marked `#`: ```python # Python 3 with requests (pip install requests). import requests API = "https://ugleh.com/gridsearch/api/v1" answer = requests.get(f"{API}/themes", timeout=60, params={"width": 15, "height": 15, "themers": "15a,15a,11a,11a", "limit": 5}, headers={"User-Agent": "my-theme-helper/1.0 (you@example.com)"}) answer.raise_for_status() page = answer.json() print(page["counts"]["layouts"], "layouts hold these themers") for layout in page["results"]: w = layout["width"] rows = [list(layout["grid"][i:i + w]) for i in range(0, len(layout["grid"]), w)] for t in layout["themers"]: # mark each themer's squares with # for k in range(t["length"]): across = t["direction"] == "across" rows[t["row"] - 1 + (0 if across else k)][t["col"] - 1 + (k if across else 0)] = "#" print(layout["puzzles"], "puzzles, the newest:", layout["examples"][0]["link"]) print("\n".join("".join(row) for row in rows), end="\n\n") ``` ## GET /search Whole grids that fit a pattern, as the search page finds them. A grid fits when every square the pattern sets matches, either as published or turned or flipped any of the eight ways. Each puzzle comes once, turned to line up with the pattern if it had to be. Newest first. Leave out `pattern` for every grid of the size. Parameters: - `width`, `height`: required (unless `code`). The pattern's size, 1 to 64. Unless `grid_width` or `grid_height` is set, also the size of the grids searched. - `pattern`: width*height characters of `.`, `-` and `_`. Default: all `_`. - `code`: optional, a grid code in place of `width`, `height` and `pattern`, such as `15.ASA3SA27aN2aA27CA3C`. - `grid_width`, `grid_height`: size of the grids to search: a number, a comparison, or `any`. In a larger grid the pattern sits in the top-left corner. - `outlet`: one outlet, by name or code from /outlets, such as `nyt`, `lat`, `usatoday`, `wapo` or `LA Times`. Default: all. - `days`: days the puzzle ran: `mon`, `tue`, `wed`, `thu`, `fri`, `sat`, `sun` (or full names), comma-separated. - `blocks`: number of black squares: a number or a comparison, such as `<=38`. - `words`: number of entries (across and down runs of two or more white squares), such as `78` or `>=72`. - `words_N`: entries of length N, N from 3 to 64, such as `words_15=>=4`. Use as many as you like. - `symmetry`: `rot180` (the usual American symmetry), `rot90`, `mirror_lr`, `mirror_tb`, `mirror_diag`, `mirror_anti`, `any` or `none`. Applies to the grid as shown. - `limit`: results per page, 1 to 100. Default 50. - `cursor`: the `next_cursor` of the previous page. - `image`: `svg` adds an `svg` field to each result. - `grid_format`: `text` (default) or `code`, which gives each grid as `code` in place of `grid`. Comparisons: a number means exactly that many; or put `>=`, `<=`, `>` or `<` before it. Encode them in URLs like any value (`words=%3E%3D72`); HTTP libraries do this for you, and a raw `>=` also works. Answer: - `counts` (first page only): `matches` (every grid that fits), `transformed` (how many had to be turned or flipped), `exact` (how many are the pattern exactly, as published, with `_` read as white), `compared` (grids that passed the filters and were big enough to compare). - `results`: the page of grids. Each has `id` (GridSearch's number; use with /grids), `xdid` (id in the xd Crossword Corpus, or null for puzzles added since), `outlet`, `date` (YYYY-MM-DD), `weekday`, `width`, `height`, `grid` (or `code`), `blocks`, `words`, `link` (the puzzle's page elsewhere, or null), `transform`, `exact`, and `svg` if asked for. - `transform`: how the published grid was turned to fit: `none`, `rotate90`, `rotate180`, `rotate270` (clockwise), `mirror_lr` (left to right), `mirror_tb` (top to bottom), `mirror_diag` (across the diagonal from top left), `mirror_anti` (across the other diagonal). - `next_cursor`: send it as `cursor` for the next page; null on the last page. Example: every 15x15 New York Times grid with at least four 15-letter entries, two to a page: ``` curl -G --compressed https://ugleh.com/gridsearch/api/v1/search -d width=15 -d height=15 -d outlet=nyt --data-urlencode 'words_15=>=4' -d limit=2 ``` ```json { "counts": { "matches": 1035, "transformed": 0, "exact": 0, "compared": 1035 }, "results": [ { "id": 162451, "xdid": null, "outlet": "New York Times", "date": "2026-11-19", "weekday": "Thursday", "width": 15, "height": 15, "grid": "---.----.---------.----.---------------------------.---.--------..-----.---------------------.----..----....----.----....----..----.---------------------.-----..--------.---.---------------------------.----.---------.----.---", "blocks": 33, "words": 74, "link": "https://www.xwordinfo.com/Crossword?date=11/19/2026", "transform": "none", "exact": false }, { "id": 161222, "xdid": "nyt2026-10-16", "outlet": "New York Times", "date": "2026-10-16", "weekday": "Friday", "width": 15, "height": 15, "grid": "-----.---.--------------------------------------.-------.-------.-----.---------.....-----.-------------....---------....-------------.-----.....---------.-----.-------.-------.--------------------------------------.---.-----", "blocks": 32, "words": 68, "link": "https://crosswordreference.com/puzzle/xd/nyt2026-10-16", "transform": "none", "exact": false } ], "next_cursor": "WzE3OTIxMDg4MDAsIk5ldyBZb3JrIFRpbWVzIiwxNjEyMjJd" } ``` ## GET /shape Grids that hold a shape anywhere, as published (shapes are not turned or flipped). `pattern` (with `width` and `height`), or `code`, is the shape and must set at least one square. Same filters as /search, but `grid_width` and `grid_height` default to `any`. Each result has `position` (`row` and `col`, counted from 0, of the shape's top-left square where it first fits) in place of `transform` and `exact`; `counts` has only `matches` and `compared`. Example: New York Times grids with a plus sign of black squares (`_._..._._`, 3x3): ```json { "counts": { "matches": 1382, "compared": 28185 }, "results": [ { "id": 162307, "xdid": "nyt2026-11-12", "outlet": "New York Times", "date": "2026-11-12", "weekday": "Thursday", "width": 15, "height": 17, "grid": "...............---.---.---.----------.--------------.-------------...------..-----.-----..---.-------.-------.-----.--------.-----.---------.---.--------.---.---.---------...------...----.----....-------------.--------------------.---.----------.---.-----", "blocks": 55, "words": 78, "link": "https://crosswordreference.com/puzzle/xd/nyt2026-11-12", "position": { "row": 3, "col": 6 } } ], "next_cursor": "WzE3OTQ0NDE2MDAsIk5ldyBZb3JrIFRpbWVzIiwxNjIzMDdd" } ``` ## GET /heatmap For each square of the pattern, the share of matching grids with a black square there (0 to 1), or null where no matching grid has a square. Same parameters as /search except `limit`, `cursor`, `image` and `grid_format`. Reads every match, so it costs as much as a search's first page. `black` has one list per row. Example, 15x15 New York Times Monday grids (shortened): ```json { "matches": 3913, "width": 15, "height": 15, "black": [ [ 0.0496, 0.0097, 0.001, 0.0606, 0.608, ... 10 more ], [ 0.0107, 0, 0, 0.0373, 0.5827, ... 10 more ], [ 0.0015, 0, 0, 0.0197, 0.31, ... 10 more ], ... 12 more rows ] } ``` ## GET /grids/{id or xdid} One puzzle's grid as published, by `id` or `xdid`: the result fields plus `symmetry` (list) and `word_lengths` (entries of each length). `grid_format=code` gives `code` in place of `grid`. ```json { "grid": { "id": 64368, "xdid": "nyt2012-04-05", "outlet": "New York Times", "date": "2012-04-05", "weekday": "Thursday", "width": 15, "height": 15, "grid": "------.----.---------.----.--------------.---.....-----.-------.----------------.-.-.-----------.-.----..-----.-.-.-----..----.-.-----------.-.-.----------------.-------.-----.....---.--------------.----.---------.----.------", "blocks": 41, "words": 70, "link": "https://crosswordreference.com/puzzle/xd/nyt2012-04-05", "symmetry": ["rot180"], "word_lengths": { "3": 20, "4": 14, "5": 14, "6": 12, "7": 4, "11": 6 } } } ``` ## GET /grids/{id or xdid}.svg A picture of the grid: SVG, black and white, 20 units to a square. `transform` (a value from a search result) turns it the way the search showed it. ## GET /outlets and GET /sizes /outlets: every outlet with its code (`slug`, usable as `outlet`) and number of grids, largest first. /sizes: every grid size with its number of grids, most common first; `outlet` narrows it to one outlet. ```json { "outlets": [ { "name": "New York Times", "slug": "nyt", "grids": 28185 }, { "name": "Newsday", "slug": "newsday", "grids": 10562 }, { "name": "LA Times", "slug": "lat", "grids": 10519 }, ... 172 more outlets ] } ``` ## GET / Lists the endpoints and these docs. ## Paging Results come newest first (layouts from /themes most used first), 50 a page unless `limit` says otherwise (at most 100). For the next page, repeat the request with `cursor` set to the answer's `next_cursor`; it is null on the last page. A page costs the server about the same whatever its size, so fetch 100 at a time when you want everything. Only the first page has `counts`, except on /themes, where every page does. ## Limits Per address: 600 requests a minute in all (bursts of 200); of those, 120 a minute to /themes, /search, /shape and /heatmap (bursts of 60); 3 at once. Everyone together: 6 at once. Past a limit: 429 with `Retry-After` (seconds); wait and retry. Answers are cached (searches 10 minutes, lists an hour, single grids a day), but a cached answer still counts. A search past 5 seconds (10 for /shape and /themes) stops with 503 `too_slow`: narrow it with `outlet` or a size. The search page's own endpoints (searchgrids.php and the rest) are for the page: programs get 403 there and should use this API. ## Errors Every error is JSON with `error` (for programs) and `message` (for people): ```json { "error": "invalid_parameter", "message": "pattern must have width \u00d7 height = 225 characters; it has 3." } ``` - 400 `invalid_parameter`: a parameter is missing, unknown or out of range; the message says which. - 404 `not_found`: no such endpoint, or no grid with that id or xdid. - 405 `method_not_allowed`: only GET (and HEAD). - 429 `rate_limited`: over a limit; wait `Retry-After` seconds. - 503 `too_slow`: the search took too long; narrow it. - 503 `unavailable`: something failed on the server; try again in a minute. ## Grid codes (optional) You never need these: everything works with `width`, `height` and `pattern`. A grid code is a shorter way to write the same grid, the one the search page keeps in its address bar: https://ugleh.com/gridsearch/#g=15.ASA3SA27aN2aA27CA3C . Send `code` in place of `width`, `height` and `pattern`; add `grid_format=code` to get codes back. A finished 15x15 grid is 225 characters as text and usually 40 to 50 as a code. To open a code in the search page: https://ugleh.com/gridsearch/#g=CODE How a code is written: 1. The size: `15` for 15x15, or `15x21` for 15 wide and 21 tall. A code that is only a size is a grid of wildcards. 2. A separator: `.` for a grid that may have wildcards, `-` for one with none. 3. Letters, taking the squares row by row from the top left. Letters count from 0: `A`-`Z` are 0-25, `a`-`z` are 26-51. After `.`, each letter is three squares, each 0 (wildcard `_`), 1 (white `-`) or 2 (black `.`), as a base-3 number with the first square as the most significant digit: `A` is `___`, `S` (18) is `.__`, `a` (26) is `...`. After `-`, each letter is five squares, each 0 (white) or 1 (black), in base 2: `A` is `-----`, `f` (31) is `.....`. 4. Repeats: a number after a letter repeats it that many more times (`A21` is 22 `A`s). A pair is written as two letters; a count is never 0. 5. Letters of all zeros at the end are left off. When the last letter runs past the grid's last square, the extra squares are ignored. Of the two forms the shorter is used, so a grid always has the same code. `15.ASA3SA27aN2aA27CA3C` row by row: ``` ___.___________ ___.___________ _______________ _______________ _______________ _______________ _______________ ...---------... _______________ _______________ _______________ _______________ _______________ ___________.___ ___________.___ ``` Searching with it, codes back: ```json { "counts": { "matches": 220, "transformed": 160, "exact": 0, "compared": 23359 }, "results": [ { "id": 161889, "xdid": "nyt2026-11-02", "outlet": "New York Times", "date": "2026-11-02", "weekday": "Monday", "width": 15, "height": 15, "code": "15-CAQCAQA3cA2IBDQCBAcAHAQIBYQCA2HA3BAIBAI", "blocks": 34, "words": 74, "link": "https://crosswordreference.com/puzzle/xd/nyt2026-11-02", "transform": "mirror_lr", "exact": false }, { "id": 161179, "xdid": "nyt2026-10-15", "outlet": "New York Times", "date": "2026-10-15", "weekday": "Thursday", "width": 15, "height": 15, "code": "15-CBACBACBA2YAcAACABBDcAHYQQAIAAHADA2QIAQIAQI", "blocks": 38, "words": 74, "link": "https://crosswordreference.com/puzzle/xd/nyt2026-10-15", "transform": "none", "exact": false } ], "next_cursor": "WzE3OTIwMjI0MDAsIk5ldyBZb3JrIFRpbWVzIiwxNjExNzld" } ``` Reading and writing codes in Python (these agree with the search page's own code; GridSearch's tests check them on thousands of grids): ```python import re LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" # After the size: '.' = 3 squares per letter in base 3, '-' = 5 squares per letter in base 2. MODES = {".": (3, 3, "_-."), "-": (5, 2, "-.")} # squares per letter, base, the square for each digit def decode_grid(code): """'15.A18GA34G' -> (15, 15, '___...'): width, height, and the grid row by row.""" m = re.fullmatch(r"(\d{1,2})(?:x(\d{1,2}))?(?:([.-])((?:[A-Za-z](?:[1-9]\d{0,3})?)*))?", code) if not m: raise ValueError(f"not a grid code: {code!r}") width, height = int(m[1]), int(m[2] or m[1]) per, base, squares = MODES[m[3] or "."] cells = width * height symbols = [] for letter, more in re.findall(r"([A-Za-z])(\d*)", m[4] or ""): symbols += [LETTERS.index(letter)] * (1 + int(more or 0)) symbols += [0] * (-(-cells // per) - len(symbols)) # left-off letters are all zero grid = "" for symbol in symbols: group = "" for _ in range(per): group = squares[symbol % base] + group symbol //= base grid += group return width, height, grid[:cells] def encode_grid(width, height, grid): """(15, 15, '___...') -> '15.A18GA34G', using '-' when there are no wildcards and that is shorter.""" size = str(width) if width == height else f"{width}x{height}" def letters(mode): per, base, squares = MODES[mode] symbols = [] for i in range(0, len(grid), per): symbol = 0 for k in range(per): symbol = symbol * base + (squares.index(grid[i + k]) if i + k < len(grid) else 0) symbols.append(symbol) while symbols and symbols[-1] == 0: # leave off trailing zeros symbols.pop() out, i = "", 0 while i < len(symbols): j = i while j < len(symbols) and symbols[j] == symbols[i]: j += 1 letter, run = LETTERS[symbols[i]], j - i out += letter if run == 1 else letter * 2 if run == 2 else f"{letter}{run - 1}" i = j return out general = letters(".") code = f"{size}.{general}" if general else size if "_" not in grid: compact = f"{size}-{letters('-') or 'A'}" if len(compact) < len(code): code = compact return code ``` ## Examples The same jobs in Python, JavaScript, Shell (bash with curl and jq) and PHP. ### Every match, page by page (follows next_cursor, waits on 429) Python: ```python # Python 3 with requests (pip install requests). import time import requests API = "https://ugleh.com/gridsearch/api/v1" session = requests.Session() session.headers["User-Agent"] = "my-grid-study/1.0 (you@example.com)" def search(**params): """Every grid that fits, newest first, a page at a time.""" params["limit"] = 100 while True: answer = session.get(f"{API}/search", params=params, timeout=60) if answer.status_code == 429: # over a limit: wait as long as asked time.sleep(int(answer.headers.get("Retry-After", "5"))) continue if not answer.ok: raise RuntimeError(answer.json()["message"]) page = answer.json() yield from page["results"] if not page["next_cursor"]: return params["cursor"] = page["next_cursor"] # Times 15x15 grids with at least four 15-letter entries, printed row by row (. black, - white). for grid in search(width=15, height=15, outlet="nyt", words_15=">=4"): w = grid["width"] print(grid["date"], grid["weekday"], grid["words"], "words", grid["link"]) for start in range(0, len(grid["grid"]), w): print(grid["grid"][start:start + w]) ``` JavaScript: ```javascript // Node 18 and later (save as search.mjs), or a module script in a web page. const API = "https://ugleh.com/gridsearch/api/v1"; // Name your program. Browsers send their own User-Agent, so leave it out in a web page. const headers = {"User-Agent": "my-grid-study/1.0 (you@example.com)"}; /** Every grid that fits, newest first, a page at a time. */ async function* search(params) { const query = new URLSearchParams({...params, limit: 100}); while (true) { const answer = await fetch(`${API}/search?${query}`, {headers}); if (answer.status === 429) { // over a limit: wait as long as asked const seconds = Number(answer.headers.get("Retry-After") ?? 5); await new Promise((resume) => setTimeout(resume, seconds * 1000)); continue; } if (!answer.ok) throw new Error((await answer.json()).message); const page = await answer.json(); yield* page.results; if (!page.next_cursor) return; query.set("cursor", page.next_cursor); } } // Times 15x15 grids with at least four 15-letter entries, printed row by row (. black, - white). for await (const grid of search({width: 15, height: 15, outlet: "nyt", words_15: ">=4"})) { console.log(grid.date, grid.weekday, grid.words, "words", grid.link); for (let start = 0; start < grid.grid.length; start += grid.width) { console.log(grid.grid.slice(start, start + grid.width)); } } ``` Shell: ```bash # Bash, with curl and jq. curl waits and asks again when the API says it is over a limit. API=https://ugleh.com/gridsearch/api/v1 cursor=() while :; do page=$(curl -sS --compressed --retry 5 -A 'my-grid-study/1.0 (you@example.com)' -G "$API/search" \ -d width=15 -d height=15 -d outlet=nyt --data-urlencode 'words_15=>=4' -d limit=100 "${cursor[@]}") if jq -e .error >/dev/null <<<"$page"; then jq -r .message <<<"$page" >&2; exit 1; fi # Times 15x15 grids with at least four 15-letter entries, printed row by row (. black, - white). jq -r '.results[] | "\(.date) \(.weekday) \(.words) words \(.link)", (.width as $w | .grid | range(0; length; $w) as $i | .[$i:$i + $w])' <<<"$page" next=$(jq -r '.next_cursor // empty' <<<"$page") [ -z "$next" ] && break cursor=(-d "cursor=$next") done ``` PHP: ```php true, CURLOPT_ENCODING => '', // accept gzip CURLOPT_TIMEOUT => 60, CURLOPT_USERAGENT => 'my-grid-study/1.0 (you@example.com)', CURLOPT_HEADERFUNCTION => function ($curl, string $header) use (&$wait): int { if (preg_match('/^Retry-After:\s*(\d+)/i', $header, $m)) $wait = (int) $m[1]; return strlen($header); }, ]); while (true) { $body = curl_exec($curl); if ($body === false) throw new RuntimeException(curl_error($curl)); $status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE); if ($status !== 429) break; sleep($wait); // over a limit: wait as long as asked } $answer = json_decode($body, true, flags: JSON_THROW_ON_ERROR); if ($status !== 200) throw new RuntimeException($answer['message']); return $answer; } /** Every grid that fits, newest first, a page at a time. */ function search(array $params): Generator { $params['limit'] = 100; do { $page = call('/search', $params); yield from $page['results']; $params['cursor'] = $page['next_cursor']; } while ($params['cursor']); } // Times 15x15 grids with at least four 15-letter entries, printed row by row (. black, - white). foreach (search(['width' => 15, 'height' => 15, 'outlet' => 'nyt', 'words_15' => '>=4']) as $grid) { echo "{$grid['date']} {$grid['weekday']} {$grid['words']} words {$grid['link']}\n"; echo implode("\n", str_split($grid['grid'], $grid['width'])), "\n"; } ``` ### One grid, row by row, and its SVG picture Python: ```python # Python 3 with requests (pip install requests). import requests API = "https://ugleh.com/gridsearch/api/v1" session = requests.Session() session.headers["User-Agent"] = "my-grid-study/1.0 (you@example.com)" # One grid, by its xd id or GridSearch id, printed row by row (. black, - white). answer = session.get(f"{API}/grids/nyt2012-04-05", timeout=60) if not answer.ok: raise RuntimeError(answer.json()["message"]) grid = answer.json()["grid"] print(grid["date"], grid["weekday"], grid["words"], "words, symmetry:", ", ".join(grid["symmetry"])) w = grid["width"] for start in range(0, len(grid["grid"]), w): print(grid["grid"][start:start + w]) # Its picture picture = session.get(f"{API}/grids/nyt2012-04-05.svg", timeout=60) picture.raise_for_status() with open("nyt2012-04-05.svg", "wb") as file: file.write(picture.content) ``` JavaScript: ```javascript // Node 18 and later (save as grid.mjs). import {writeFile} from "node:fs/promises"; const API = "https://ugleh.com/gridsearch/api/v1"; const headers = {"User-Agent": "my-grid-study/1.0 (you@example.com)"}; // One grid, by its xd id or GridSearch id, printed row by row (. black, - white). const answer = await fetch(`${API}/grids/nyt2012-04-05`, {headers}); if (!answer.ok) throw new Error((await answer.json()).message); const {grid} = await answer.json(); console.log(grid.date, grid.weekday, grid.words, "words, symmetry:", grid.symmetry.join(", ")); for (let start = 0; start < grid.grid.length; start += grid.width) { console.log(grid.grid.slice(start, start + grid.width)); } // Its picture const picture = await fetch(`${API}/grids/nyt2012-04-05.svg`, {headers}); if (!picture.ok) throw new Error(`The picture answered ${picture.status}`); await writeFile("nyt2012-04-05.svg", await picture.text()); ``` Shell: ```bash # Bash, with curl and jq. API=https://ugleh.com/gridsearch/api/v1 UA='my-grid-study/1.0 (you@example.com)' # One grid, by its xd id or GridSearch id, printed row by row (. black, - white). curl -sS --compressed --retry 5 -A "$UA" "$API/grids/nyt2012-04-05" | jq -r '.grid | "\(.date) \(.weekday) \(.words) words, symmetry: \(.symmetry | join(", "))", (.width as $w | .grid | range(0; length; $w) as $i | .[$i:$i + $w])' # Its picture curl -sS --fail --retry 5 -A "$UA" -o nyt2012-04-05.svg "$API/grids/nyt2012-04-05.svg" ``` PHP: ```php true, CURLOPT_ENCODING => '', // accept gzip CURLOPT_TIMEOUT => 60, CURLOPT_USERAGENT => 'my-grid-study/1.0 (you@example.com)', ]); $body = curl_exec($curl); if ($body === false) throw new RuntimeException(curl_error($curl)); $status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE); if ($status !== 200) throw new RuntimeException("$url answered $status: $body"); return $body; } // One grid, by its xd id or GridSearch id, printed row by row (. black, - white). $grid = json_decode(get(API . '/grids/nyt2012-04-05'), true, flags: JSON_THROW_ON_ERROR)['grid']; echo "{$grid['date']} {$grid['weekday']} {$grid['words']} words, symmetry: ", implode(', ', $grid['symmetry']), "\n"; echo implode("\n", str_split($grid['grid'], $grid['width'])), "\n"; // Its picture file_put_contents('nyt2012-04-05.svg', get(API . '/grids/nyt2012-04-05.svg')); ```