Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

examples of API set query

Project: API Tutorial
Views: 778
Kernel: Python 3 (system-wide)

Use API query to set values in CoCalc database

# import utility definitions %run ./01-utils.ipynb
# 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) 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) print("\nupdated project info:") pp.pprint(response)
# Query B - set one attribute in a map field # This example uses the 'accounts' table account_id = 'enter the account id from notebook 02-get-my-account-id.ipynb' # set jupyter_classic editor option to False payload = {"query":{"accounts":{"account_id":account_id, "editor_settings":{"jupyter_classic":False}}}} response = call_api("query", payload) 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) print("\nupdated editor_settings jupyter_classic:") pp.pprint(response)