SharedPublic / PYTHON / 03-qet-query.ipynbOpen in CoCalc
Examples of API get query

Use API query to get values from CoCalc database

# import utility definitions
%run ./01-utils.ipynb
# load credentials
uinfo = load_user_info("../../SECRET/testuser.yaml")
# 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'},
# 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'}]}}
# 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'}}}