| Hosted by CoCalc | Download
Kernel: Python 3 (system-wide)

Examples of Specialized API Calls

Calls that use message type other than query.

# import utility definitions %run ./01-utils.ipynb
# Example A - create project # It is possible to create two projects with the same name and description; such projects will have different project_id attributes. For that reason, we check first if a matching project has already been created, and skip the creation step if it has already been done. title = 'SAMPLE PROJECT' description = '#apitest' payload = {"query":{"projects":[{"project_id":None, "title":title, "description":None}]}} response = call_api("query", payload) matching_projects = response['query']['projects'] lmatch = len(matching_projects) print('found {} projects with title "{}"'.format(lmatch, title)) myproj = None if lmatch > 0: print("skipping project creation, already have these projects:") pp.pprint(matching_projects) myproj = matching_projects[0]['project_id'] else: print("creating project - note project_id") payload = {'title' :title, 'description':description} response = call_api('create_project', payload) pp.pprint(response) try: myproj = response['project_id'] print("new project id = {}".format(myproj)) except: print('project not created')
# Example B - create text file # Directory will be created if it doesn't already exist. # Text file will be overwritten if it already exists. # If you run this while the project is stopped, the call may fail with ECONNREFUSED. path = "TEXT/sample.md" text = """ # Sample markdown file ## Section 1 section 1 contents """ print("creating text file") payload = {'project_id' :myproj, 'content' :text, 'path' :path} response = call_api('write_text_file_to_project', payload) pp.pprint(response)