Skip to content

Commit

Permalink
add resources category example
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasCARPi committed Oct 27, 2023
1 parent 20849f1 commit 3963753
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
generated/
openapi.yaml
html
venv
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"packageName": "elabapi_python",
"pythonPackageName": "elabapi_python",
"projectName": "elabapi-python",
"packageVersion": "0.3.1",
"packageVersion": "0.4.0",
"packageUrl": "https://github.com/elabftw/elabapi-python"
}
48 changes: 48 additions & 0 deletions examples/11-resources-categories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python

###############
# DESCRIPTION #
##############
# In this script, we will create a resource category and patch it
##############

# the python library for elabftw
import elabapi_python

#########################
# CONFIG #
#########################
# replace with the URL of your instance
API_HOST_URL = 'https://elab.local:3148/api/v2'
# replace with your api key
API_KEY = 'apiKey4Test'
#########################
# END CONFIG #
#########################

# Configure the api client
configuration = elabapi_python.Configuration()
configuration.api_key['api_key'] = API_KEY
configuration.api_key_prefix['api_key'] = 'Authorization'
configuration.host = API_HOST_URL
configuration.debug = False
configuration.verify_ssl = False

# create an instance of the API class
api_client = elabapi_python.ApiClient(configuration)
# fix issue with Authorization header not being properly set by the generated lib
api_client.set_default_header(header_name='Authorization', header_value=API_KEY)

#### SCRIPT START ##################

# Load the items types api
itemsTypesApi = elabapi_python.ItemsTypesApi(api_client)

# create one, we provide a title on creation but it's not mandatory
response = itemsTypesApi.post_items_types_with_http_info(body={'title': "My freshly created category"})
# 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
locationHeaderInResponse = response[2].get('Location')
print(f'The newly created resource category is here: {locationHeaderInResponse}')
itemId = int(locationHeaderInResponse.split('=').pop())
# now change the title, and body and color
itemsTypesApi.patch_items_type(itemId, body={'title': 'The new title', 'body': 'Main content text', 'color': '#f5c211'})
4 changes: 4 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ Read a CSV file containing a list of antibodies and import them in the resource
# 10-date-time-conversions.py

Work with date-time data formats with a demonstration of doing statistics with experiments data.

# 11-resources-categories.py

Create and edit a Resources Category (Items types).

0 comments on commit 3963753

Please sign in to comment.