Using the Dynalist API in Python (With example code to export flattened document)

What does it do? - It returns a whole document, flat, not necessarily in perfect order, in ASCII text

How do I run it? - Anywhere that python runs. My favorite place is Colab. Paste it in and press shift-Enter to run it.

Why did you make it? - Nobody on the Dynalist Forums has ever admitted to using the read API, and I am trying to learn programming, so I dived in an made something that uses the read API.

Why are you sharing it? - I’m hoping other folks will take my code, mess around and make it do cool things. Maybe you can get dynalist nodes to import into other apps via IFTTT or something? Maybe you can make cool new Export formats? Reading a document into Python is the first step to any number of cool ideas. In the science world, when one team makes a breakthrough, many others make similar breakthroughs independently just because they know it’s possible. So here’s some inspiration. Plus I got to learn a bit of programming.

import requests
import json

print("See your API token at https://dynalist.io/developer \n \
See your document ID in your browser address bar: \
 _____dynalist.io/d/THIS_PART <--")
token=input("Paste your API token: ") or "optional_put_token_here"
file_id=input("Paste your document ID: ") or "optional_put_file_id_here"

r=requests.post("https://dynalist.io/api/v1/doc/read", \
                json = {"token": token, "file_id": file_id})
doc_dict = r.json()
doc_list_of_dicts = doc_dict["nodes"]
dict1 = {}
str1 = ""

for i in range(len(doc_list_of_dicts)):
    str1 = str1 + doc_list_of_dicts[i]["content"] + "\n"

print(str1)
1 Like

I’ve been informed there’s actually a bunch of python for dynalist out there