How the Download Center works
Request a file, poll until it is ready, then fetch it. The same pattern covers award, account, and archive files.
The Download Center turns filters into files. Every download, whether from Custom Award Data, Custom Account Data, or an Advanced Search results table, follows the same three steps: ask for a file, wait for it, fetch it.
Why it works this way
Files can hold millions of rows, so they're built by a background job instead of inside the request. The request returns right away with a status_url to poll and the file_url the finished zip will live at. The Paging and downloads page shows the loop in code.
Before you ask
The site checks size before it queues a search download: download/count says how many rows a filter would produce and whether that's over the limit. It also fills its agency and budget function pickers from the list endpoints below, which you can use to build valid requests.
The calls, in order
To fill the agency picker
For account data: the budget function picker
Before a search download
Checks the row count against the download limit.
Custom Award Data: submit the request
Returns a file name and a status URL right away.
Custom Account Data: submit the request
From Advanced Search: download awards, transactions, and subawards together
Every few seconds until status is finished
When it finishes, file_url points to the zip.
Award Data Archive: list the prepackaged files
Sources
Traced from these files in the public usaspending-website repo: