Get API JSON request from web request?

So I was wondering, is there a way to get the JSON call to the API that replicates whatever query you make in the web portal? I’m thinking of a case where you make a replication package, or you simply want to keep the API call in a code that can replicate the query that you made, all while being able to explore the data in the web.

Is this a hidden feature that exists, or perhaps something that is in the works?

Hi Alvaro, thanks for the question! The short answer is no, not yet, though we hope to get there someday.

The reason for this is that the APIs are not yet feature-equivalent to the web extract system. There are things the web system can do that the API doesn’t do yet, so if the API were given a JSON definition from a web-created extract that used one or more of those features, it would not be able to process it.

We do have a goal of exposing the JSON definitions to users once our APIs are feature-complete, but we have no timeline for that as of yet.

Hi, thanks a lot, I found in fact a way to get the JSON call like this:

my_headers = {"Authorization": my_key}

extracts = requests.get(
    "https://api.ipums.org/extracts?product=nhgis&version=v1",
    headers=my_headers
    )
for extract in extracts.json():
    if extract["number"] == *NUMBER*:
        wanted_extract = extract

but of course, this runs the risk of getting an error because of what you mentioned?

I’ll try and see if I can make an extract that suits my needs and also works with the API, it’s very tricky for me to come up with a request directly as a JSON key without browsing the web application, but I really need to be able to replicate the requests from Python.

Exactly right, there’s no guarantee that an extract definition retrieved in that way will work via the API.

Are you aware of the ipumspy library? It makes forming API requests more straightforward as you can specify what you want in a Python-native way rather than having to try to form JSON payloads directly. You may find that helpful.