This requires that you have access to the Datasets API
The Enin Datasets API is built for downloading large datasets.
We strongly recommend either:
You should not re-download data every time you need it. Instead:
When testing and setting up your integration, it's fine to fetch data multiple times. To avoid downloading too much data during testing, start with a small limit (e.g., 100 rows). However, once you remove the limit, expect datasets to be very large (e.g., 100,000+ rows per company flag type).
Here is a python example of how you to get a list of organization numbers that has a specific flag
from datetime import datetime
import requests
import json
password = "my_basic_auth_password"
username = "my_basic_auth_username"
response = requests.get(
"https://api.enin.ai/datasets/v1/dataset/company-flag-history-composite",
params={
"file_type": "json",
"snapshot_date": "2025-02-11",
"keep_only_fields": "company.org_nr",
"company_flag_type.company_flag_type_key": "recent_high_risk_event",
"limit": 100 # Start with 100 to test.
},
auth=(username, password),
)
if response.ok:
company_composite_list = response.json()
org_nrs = [ comp.get("company", {}).get("org_nr", "unknown") for comp in company_composite_list ]
print(org_nrs)
filename = f"recent_high_risk_event_{datetime.now():%Y%m%d_%H%M%S}.json"
with open(filename, "w") as new_file:
json.dump(org_nrs, new_file, indent=4)
else:
print("ERROR")
print(response.status_code)
print(response.text)
response = requests.get(
"https://api.enin.ai/datasets/v1/dataset/company-flag-history-composite",
params={
"file_type": "json",
"snapshot_date": "2025-02-11",
"keep_only_fields": "company.org_nr",
"company_flag_type.company_flag_type_key": "recent_high_risk_event",
"limit": 100 # Start with 100 to test.
},
auth=(username, password),
)
With snapshot_date
we are asking for any company-flags for the date "2025-02-11" (11th february 2025). The earlest snapshot date available for you will be yesterday, since each flag is calcluated at night.
keep_only_fields
and file_type
are generic datasets query params that you can use for most datasets endpoints. Here we say that we want to only keep the company -> org_nr from the company-flag-history-composite. This will speed up the endpoint and reduce the file size that you recieve. (See selecting-fields-and-entities-with-the-datasets-api)
"company_flag_type.company_flag_type_key": "recent_high_risk_event",
will ensure that you only get company-flags for that certain type.
params={ "company_flag_type.company_flag_type_key": "in:recent_high_risk_event,company_setup_change_major,possible_change_ownership"}
https://api.enin.ai/datasets/v1/dataset/company-flag-history-composite?file_type=json&snapshot_date=2025-02-11&keep_only_fields=company.org_nr&company_flag_type.company_flag_type_key=recent_high_risk_event&limit=100
[
{"org_nr": "987654162"}, {"org_nr": "987654162"} , {"org_nr": "987654162"} , {"org_nr": "987654162"} // ...
]
if response.ok:
company_composite_list = response.json()
org_nrs = [ comp.get("company", {}).get("org_nr", "unknown") for comp in company_composite_list ]
print(org_nrs)
If there was a successful response we convert the json into a python list of objects, and print them out. (Remove the print as soon as you remove your limit, unless you want to print out thousands of org numbers in your console).
company_composite_list = response.json()
makes it easy for us to work with and parse the data.
org_nrs = [ comp.get("company", {}).get("org_nr", "unknown") for comp in company_composite_list ]
Here we get all composites -> company -> org_nr
Now that we have the organization numbers, we create a file, and save all the organization numbers to a .json file.
{datetime.now():%Y%m%d_%H%M%S}
Makes a timestamp string so that each time you run this function, a new file will be created since the name is unique. filename = f"recent_high_risk_event{datetime.now():%Y%m%d_%H%M%S}.json"
with open(filename, "w") as new_file:
json.dump(org_nrs, new_file, indent=4)
The result is a file that looks like:
recent_high_risk_event_20250212_160448.json
["987654162", "987654162", "987654162" ]
You will now have a script that has minimum dependencies, and that downloads and saves a list of companies to a json file.
If you want to download more than one company flag type, you must ensure that your list is unique, since you will get one org_nr per company-flag-type in the list.