CoCalc Shared FilesPublic / PYTHON / 04-set-query.ipynbOpen in CoCalc with one click!
Authors: Hal Snyder, ℏal Snyder
Views : 46
Description: examples of API set query

Use API query to set values in CoCalc database

In [ ]:
# import utility definitions %run ./01-utils.ipynb
In [ ]:
# load credentials uinfo = load_user_info("../../SECRET/testuser.yaml")
In [ ]:
# Query A - update project description # Modify my_proj_id to be the id of one of your projects, obtained from 03-get-query.ipynb my_proj_id = '..enter your project_id here..' new_desc = "New Project Description" # Do a set query to change the description payload = {"query":{"projects":{"project_id":my_proj_id, "description":new_desc}}} response = call_api("query", payload, uinfo['api_key']) print("response to set query:") pp.pprint(response) # Do a get query to confirm the new setting payload = {"query":{"projects":{"project_id":my_proj_id, "description":None}}} response = call_api("query", payload, uinfo['api_key']) print("\nupdated project info:") pp.pprint(response)
In [ ]:
# Query B - set one attribute in a map field # This example uses the 'accounts' table account_id = uinfo['account_id'] # set jupyter_classic editor option to False payload = {"query":{"accounts":{"account_id":account_id, "editor_settings":{"jupyter_classic":False}}}} response = call_api("query", payload, uinfo['api_key']) print("response to set query:") pp.pprint(response) # get list of editor_settings to confirm the update payload = {"query":{"accounts":{"account_id":account_id, "editor_settings":None}}} response = call_api("query", payload, uinfo['api_key']) print("\nupdated editor_settings jupyter_classic:") pp.pprint(response)
In [ ]: