Skip to content

Commit 3963753

Browse files
committed
add resources category example
1 parent 20849f1 commit 3963753

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
generated/
22
openapi.yaml
33
html
4+
venv

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"packageName": "elabapi_python",
33
"pythonPackageName": "elabapi_python",
44
"projectName": "elabapi-python",
5-
"packageVersion": "0.3.1",
5+
"packageVersion": "0.4.0",
66
"packageUrl": "https://github.com/elabftw/elabapi-python"
77
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
3+
###############
4+
# DESCRIPTION #
5+
##############
6+
# In this script, we will create a resource category and patch it
7+
##############
8+
9+
# the python library for elabftw
10+
import elabapi_python
11+
12+
#########################
13+
# CONFIG #
14+
#########################
15+
# replace with the URL of your instance
16+
API_HOST_URL = 'https://elab.local:3148/api/v2'
17+
# replace with your api key
18+
API_KEY = 'apiKey4Test'
19+
#########################
20+
# END CONFIG #
21+
#########################
22+
23+
# Configure the api client
24+
configuration = elabapi_python.Configuration()
25+
configuration.api_key['api_key'] = API_KEY
26+
configuration.api_key_prefix['api_key'] = 'Authorization'
27+
configuration.host = API_HOST_URL
28+
configuration.debug = False
29+
configuration.verify_ssl = False
30+
31+
# create an instance of the API class
32+
api_client = elabapi_python.ApiClient(configuration)
33+
# fix issue with Authorization header not being properly set by the generated lib
34+
api_client.set_default_header(header_name='Authorization', header_value=API_KEY)
35+
36+
#### SCRIPT START ##################
37+
38+
# Load the items types api
39+
itemsTypesApi = elabapi_python.ItemsTypesApi(api_client)
40+
41+
# create one, we provide a title on creation but it's not mandatory
42+
response = itemsTypesApi.post_items_types_with_http_info(body={'title': "My freshly created category"})
43+
# the response location for this endpoint is a bit different from the rest, it is the full URL: https://elab.example.org/api/v2/items_types/admin.php?tab=4&templateid=15
44+
locationHeaderInResponse = response[2].get('Location')
45+
print(f'The newly created resource category is here: {locationHeaderInResponse}')
46+
itemId = int(locationHeaderInResponse.split('=').pop())
47+
# now change the title, and body and color
48+
itemsTypesApi.patch_items_type(itemId, body={'title': 'The new title', 'body': 'Main content text', 'color': '#f5c211'})

examples/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ Read a CSV file containing a list of antibodies and import them in the resource
4545
# 10-date-time-conversions.py
4646

4747
Work with date-time data formats with a demonstration of doing statistics with experiments data.
48+
49+
# 11-resources-categories.py
50+
51+
Create and edit a Resources Category (Items types).

0 commit comments

Comments
 (0)