Sometimes it can be useful to download rows that have changed since some date or timestamp
in a dataset. This can be done by using the filter value update_timestamp
and
one of the operators GT
or GTE
.
As filter value you can use a date on the format: YYYY-MM-DD
or a timestamp YYYY-MM-DDTHH:MM:SS
.
Let's try with an example:
accounts = requests.get(
"https://api.enin.ai/datasets/v1/dataset/accounts-composite",
params={
"response_file_type": "csv",
"accounts_type.accounts_type_key": "EQ:annual_company_accounts",
"update_timestamp": "GTE:2021-05-01",
"keep_only_fields": ','.join(
[
"company.name",
"company.org_nr",
"accounts.accounting_year",
"accounts_income_statement.total_operating_income",
]
)
},
auth=auth,
).content.decode()
print(accounts)
We added the filter "update_timestamp": "GTE:2021-05-01",
and our request will now retrieve any row
that has changed since 2021-05-01
in the entities we have selected in our keep_only_fields
.
Note that when using update_timestamp as a filter, any field in the entity that has changed
will trigger a change in the update timestamp. Meaning that you could experience retrieving
individual fields that have not been changed even though the update timestamp have changed.
The update timestamp only reflects that a
field in the entity has changed.
This feature will work for the following endpoints:
'/company-employment',
'/company-employment-composite',
'/dataset/accounts',
'/dataset/accounts-composite',
'/dataset/company',
'/dataset/company-composite',
'/dataset/company-risk-score-measure',
'/dataset/company-risk-score-composite',
'/dataset/company-share-ownership',
'/dataset/company-share-ownership-composite',
'/dataset/currency-exchange-rate'
Note that these endpoints will not have the update_timestamp
filter available for them
'/dataset/company-flag-history'
'/dataset/company-flag-history-composite'
'/company-flag'
'/company-flag-composite'
Getting updated rows from /dataset/company-flag-history
and /dataset/company-flag-history-composite
is not
recommended as it is a snapshot table. Use the endpoint /company-flag
instead and set the filter
looback_date
to get all new entries (flags that have been set) since that date.
Sometimes it can be useful to order the dataset you are requesting. This can be done with the
order_by_fields
query parameter. It requires fully qualified field names using dot notation.
By default the ordering is done ascending.
Let's start with just ordering companies by name:
companies = requests.get(
"https://api.enin.ai/datasets/v1/dataset/company",
params={
"limit": 5,
"response_file_type": "csv",
"company.org_nr_schema": 'NO',
"keep_only_fields": ','.join(
[
"company.name",
"company.org_nr",
]
),
"order_by_fields": 'company.name',
},
auth=auth,
).content.decode()
print(companies)
This returns:
name,org_nr
0001 INVEST AS,921826885
0001 PRODUCTION AS,919072083
001 KONSULENT1 Johansen,989258265
0047 IMPORT ROGER BERSVENDSEN,990149143
0047 OSLO AS,990893330
As you can see it sorts (lexicographically) in ascending order. You can set the ordering explicitly by the following syntax:
<field_name>:<asc|desc>
And, you can list multiple of these using comma separators (,
).
To illustrate multiple orderings, let's order on name and revenue. And because there are
very few companies with the same name, let's start from MOTORSENTER AS
which we know there
are multiple of.
accounts = requests.get(
"https://api.enin.ai/datasets/v1/dataset/accounts-composite",
params={
"response_file_type": "csv",
"company.name": "GTE:MOTORSENTER AS",
"accounts_type.accounts_type_key": "EQ:annual_company_accounts",
"accounts.accounting_year": "EQ:2018",
"keep_only_fields": ','.join(
[
"company.name",
"company.org_nr",
"accounts_income_statement.total_operating_income",
]
),
"order_by_fields": ','.join(
[
"company.name:asc",
"accounts_income_statement.total_operating_income:desc",
]
),
},
auth=auth,
).content.decode()
print(accounts)
This prints:
company.name,company.org_nr,accounts_income_statement.total_operating_income
MOTORSENTERET AS,966377607,41998000
MOTORSENTERET AS,971233974,15131000
MOTORSENTERET AS,976604628,5654000
MOTORSENTERET EIENDOM AS,987659327,410000
MOTORSENTERET HEIDAL AS,999301061,29965000
MOTORSENTERET-LIMO NORGE AS,911916797,6497000
MOTORSENTERET SELBU OG TYDAL AS,916983069,12266000
MOTORSERVICE ALTA AS,998539749,4061000
MOTOR SERVICE AS,817570852,7229000
MOTOR-SERVICE AS,914424011,819000
MOTOR-SERVICE BILSENTER AS,977199832,35394000
MOTORSERVICE DA,929710339,5176000
As you can see the names are sorted ascending, and because there are three "MOTORSENTERET AS"
with their own organization numbers, they are sorted descending by
accounts_income_statement.total_operating_income
, same applies to MOTOR SERVICE AS
further
down the list.