CoCalc Public FilesPublic / PYTHON / 03-qet-query.ipynbOpen with one click!
Authors: Hal Snyder, ℏal Snyder
Views : 94
Description: examples of API get query
Compute Environment: Ubuntu 18.04 (Deprecated)

Use API query to get values from CoCalc database

In [1]:
# import utility definitions %run ./01-utils.ipynb
In [2]:
# load credentials uinfo = load_user_info("../../SECRET/testuser.yaml")
In [ ]:
# Query A - get one record payload = {"query":{"projects":{"project_id":None, "title":None, "description":None}}} response = call_api("query", payload, uinfo['api_key']) pp.pprint(response) ## expected result - could be any project on which the api key owner is owner or collaborator # # {'event': 'query', # 'id': 'a6462afb-e45f-4b15-a98f-18e3d21ede03', # 'multi_response': False, # 'query': {'projects': [{'description': '#api #tutorial', # 'project_id': 'ef881a4a-ca29-11e7-95d6-0fea06be7bb7', # 'title': 'My First Project'},
In [ ]:
# Query B - get multiple records payload = {"query":{"projects":[{"project_id":None, "title":None, "description":None}]}} response = call_api("query", payload, uinfo['api_key']) pp.pprint(response) ## expected result - one entry for each project in the account that owns the API key # # {'event': 'query', # 'id': 'a6462afb-e45f-4b15-a98f-18e3d21ede03', # 'multi_response': False, # 'query': {'projects': [{'description': '#api #tutorial', # 'project_id': 'ef881a4a-ca29-11e7-95d6-0fea06be7bb7', # 'title': 'My First Project'}, # {'description': 'No Description', # 'project_id': 'fef71878-ca29-11e7-9871-cbc5407fc199', # 'title': 'My Second Project'}]}}
In [ ]:
# Query C - get matching record # Edit one or more of project_id, title, or description to match one of your projects payload = {"query":{"projects":{"project_id":None, "title":None, "description":"No Description"}}} response = call_api("query", payload, uinfo['api_key']) pp.pprint(response) ## expected result - matching project. In the example, the project with "No Description" # # {'event': 'query', # 'id': 'a6462afb-e45f-4b15-a98f-18e3d21ede03', # 'multi_response': False, # 'query': {'projects': {'description': 'No Description', # 'project_id': 'fef71878-ca29-11e7-9871-cbc5407fc199', # 'title': 'My Second Project'}}}
In [ ]: