|
1 | 1 | #!/usr/bin/env python |
2 | 2 | import time |
| 3 | +import json |
3 | 4 | import elabapi_python |
4 | 5 | from elabapi_python.rest import ApiException |
5 | 6 |
|
6 | 7 | # replace with your api key |
7 | 8 | my_api_key = 'apiKey4Test' |
8 | 9 |
|
9 | | -# Config |
| 10 | +# START CONFIG |
10 | 11 | configuration = elabapi_python.Configuration() |
11 | 12 | configuration.api_key['api_key'] = my_api_key |
12 | 13 | configuration.api_key_prefix['api_key'] = 'Authorization' |
13 | 14 | configuration.host = 'https://elab.local:3148/api/v2' |
14 | | -configuration.debug = True |
| 15 | +configuration.debug = False |
15 | 16 | configuration.verify_ssl = False |
16 | 17 |
|
17 | 18 | # create an instance of the API class |
18 | 19 | api_client = elabapi_python.ApiClient(configuration) |
19 | 20 | # fix issue with Authorization header not being properly set by the generated lib |
20 | 21 | api_client.set_default_header(header_name='Authorization', header_value=my_api_key) |
| 22 | +# END CONFIG |
21 | 23 |
|
22 | 24 | # create an instance of Items |
23 | 25 | items = elabapi_python.ItemsApi(api_client) |
| 26 | + |
24 | 27 | # display items with default settings |
25 | | -print(items.read_items()) |
26 | | -# display 50 items with a category id of 8 |
27 | | -print(len(items.read_items(limit=50, cat=8))) |
| 28 | +itemsList = items.read_items() |
| 29 | +print(type(itemsList)) # <-- python list |
| 30 | +print(itemsList) |
| 31 | + |
| 32 | +# fetch 50 items with a category id of 8 |
| 33 | +itemsList = items.read_items(limit=50, cat=8) |
| 34 | +print(f'Number of results: {len(itemsList)}') |
| 35 | + |
| 36 | +# if you want raw json, use _preload_content=False |
| 37 | +# get the response object directly |
| 38 | +response = items.read_items(_preload_content=False) |
| 39 | +print(response.data.decode('utf-8')) # <-- JSON string |
| 40 | +# transform it into python object from JSON |
| 41 | +data = response.json() |
| 42 | +# and pretty print the firt three elements in JSON |
| 43 | +print(json.dumps(data[0:3], indent=2)) |
0 commit comments