Using the Enin Datasets API, you can set up a API call that will return a set of companies given some filter criteria. For instance companies located in Oslo with more than 100 employees. If you also have the capability to schedule your code to run, say, once a day, you can create a watchlist that are updated every day.
We will first use the Datasets API to retrieve a list of companies that match your filter criteria, and then empty and fill a watchlist with those companies.
In this example, we make a Datasets API GET
method to select companies in Oslo that have more
than 100 employees. Then we reuse the code for emptying and filling a watchlist from the
section above to maintain a watchlist dynamically.
# Python 3.9
import requests
# Construct our datasets filters
datasets_params = {
"keep_only_fields": "company.org_nr,company.org_nr_schema", # selecting only org_nr and org_nr_schema
"company_location_business_address.country_name": "EQ:Norge", # Filtering for Norway
"company_location_business_address.municipality_name": "EQ:OSLO", # Filtering for Oslo
"company_details.employees": "GTE:100", # GT is short for "greater than"
}
companies = requests.get(
"https://api.enin.ai/datasets/v1/dataset/company-composite",
headers={
"accept": "application/json",
"Authorization": load_api_bearer_token(api_name="datasets"), # !!using the datasets api name!!
},
params=datasets_params,
).json()
# Format the companies dict, we recieve [{"company": {"org_nr": org_nr, "org_nr_schema": org_nr_schema}}, ...]
# and we want it to be [{"org_nr": org_nr, "org_nr_schema": org_nr_schema}, ...]
# when we post to the watchlist endpoint
companies = [company["company"] for company in companies]
# Empty the existing watchlist
requests.delete(
"https://api.enin.ai/analysis/v1/watchlist/6834414f-cc36-44be-8713-d00b2ef7e05d/company",
headers={
"accept": "application/json",
"Authorization": load_api_bearer_token(api_name="analysis"),
}
)
# Fill watchlist with companies
requests.post(
"https://api.enin.ai/analysis/v1/watchlist/6834414f-cc36-44be-8713-d00b2ef7e05d/company",
headers={
"accept": "application/json",
"Authorization": load_api_bearer_token(api_name="analysis"),
},
json=companies,
)