Headless Logseq on a self hosted server and add/edit data using api

Hi, I’m a software dev and new to Logseq but I find it very fascinating to write my daily journals and I want to integrate it into my daily workflow. I have used syncthing to setup sync between my linux laptop and android phone and eventually plan to move onto a flow like the one described here => My multi-devices Logseq sync setup | akhy.Write(blog).
In the above blog, the author uses a spare droplet instance (remote server) to host his logseq notes and uses syncthing to sync across all devices and his server.
Now what I want to do is something similar but I want to be able to interact with the version on server with an api. I know that Logseq does provide an api to interact with it but that api requires the gui version of Logseq to keep running. What I want to do is to run Logseq in a headless mode on the server.
I want to be able to inscribe my voice notes on the daily journal. For that I am planning to make a simple android app that records my voice notes and then transcribes them via a third party api like whisper or something else and then I want to insert those notes in the logseq daily journal. Can somebody offer some solutions for this dilemma? I know the DB version is on the way and would probably solve this issue of mine too but in the meantime what d you recommend I do?

2 Likes

I believe the best way to achieve these results is to create a Telegram chatbot with a script that uses OpenAI to convert your audio recordings into notes and subsequently send these notes to Logseq through an API that you can build and host on your server. This API will receive the text and write the content into Logseq text files.

Since Logseq keeps all data in text files, creating, editing, and adding data is not a complex task. Although I’m not aware of an official API for this purpose, the CLI project “logseq-query” might help in identifying the correct file to be edited.

Therefore, I see the complete solution as comprising three parts: (a) synchronization, (b) a custom backend API, and (c) a Telegram chatbot integrated with OpenAI.

For part (a) synchronization, you have already used Syncthing. Personally, I solved this problem with a script that automatically performs commit, push, and pull on a private Git server (I use the free version of Bitbucket). On Android, I sync folders between Android and my Linux server, and the script on the server handles commit, push, and pull. The advantage of this approach is that I keep my notes secure and with a history in Git.

To implement part (b), the custom API, you can create the backend using any language of your choice, such as Python, where an endpoint would be capable of receiving your calls on the server and writing the content into Logseq text files.

For implementing part (c), the chatbot, there are various tutorials available.

1 Like

Thanks a lot @educostadev for your answer. I just had a few questions if you don’t mind. Does manually editing/creating a file effect the working of logseq in any way? I had the preconception that logseq maintains a graph file or something similar for every entry we make though I might be wrong. Please enlighten me on this.

You’re right! You’ll have to re-index the graph on ALL clients once all the files are synced and is not possible do it via CLI. I don’t know where the re-indexed file is stored nor why the same re-indexed files does not work across multiple devices.

1 Like

Do you think these issues will be resolved in the new db version?

I am looking at a similar problem.

https://docs.logseq.com/#/page/local%20http%20server exposes the plugin API over JSON on localhost (Setting is Settings > Features > HTTP APIs server now) but I am also thinking how I might run logseq without a UI, set up sync, and use that to integrate some services…

nbb-logseq/examples/fly-io at main · logseq/nbb-logseq · GitHub is an example of a node.js service using nbb-logseq to interface with the graph…

1 Like