download_from_api_with_authentication¶
Generic download function to download data from authenticated endpoints on api.data.amsterdam.nl using the authentication/getaccesstoken.py script:
You can login as 2 types of users:
employee:
For endpoints which are only viewable when on the internal network.uses:
data={type='employee'}employee_plus credentials.
For endpoints which require a user/password which can be given, by filling in this form:
http://intranet.amsterdam.nl/kennis-beleid/dienstverlening/data/programma-datapunt/autorisatie-datapunt/and sending it to:
datapunt@amsterdam.nluses:
data={type='employee', email='<registered email>', password='<recieved password'}When using the employee_plus type add the following ENV variables:
export DATAPUNT_EMAIL=*** export DATAPUNT_PASSWORD=***Command line example using employee for tellus api’s on acc:
download_from_api_brk https://acc.api.data.amsterdam.nl/tellus/tellusdata employee TLLS/R data tellus.jsonCommand line example using employee_plus for kadaster api’s on acc:
download_from_api_brk https://acc.api.data.amsterdam.nl/brk/object/ employee_plus BRK/RS,BRK/RSN,BRK/RO data object.json
usage: download_from_api_with_authentication [-h]
url {employee,employee_plus}
scopes output_folder filename
Positional Arguments¶
url | add full endpoint, for example https://api.data.amsterdam.nl/brk/object/ |
usertype | Possible choices: employee, employee_plus Choose user type employee or employee_plus Default: “employee” |
scopes | Define scopes of the endpoints, the names can be found here: https://github.com/Amsterdam/authorization_levels/blob/master/authorization_levels.py. For example: TLLS/R or multiple: BRK/RS,BRK/RSN,BRK/RO |
output_folder | Add outputfolder location, for example: my_project_folder/data or . if you want to save in the current dir |
filename | Add filename: for example brk.json |
functions¶
-
datapunt_processing.extract.download_from_api_with_authentication.
getJsonData
(url, access_token)¶ Get a json response from a url with accesstoken.
- Args:
- url: api endpoint
- accessToken: acces token generated using the auth helper: GetAccessToken().getAccessToken(usertype=’employee_plus’, scopes=’BRK/RS,BRK/RSN/,BRK/RO’)
- Returns:
- parsed json or error message
-
datapunt_processing.extract.download_from_api_with_authentication.
parser
()¶ Parser function to run arguments from commandline and to add description to sphinx docs.