Using SilverBullet APIs to update/add to a page

I’ve looked at the API page in SilverBullet and, although I’m comfortable with APIs, I’m confused on how to use the SilverBullet API. I would assume a PUT to to add content to index.md would look something like

curl --location --request PUT 'http://192.168.86.43:3000/index.md' \
--header 'Content-Type: text/plain' \
--data '**TEST**'

Is this correct? How would I authorize this? Thanks for any help! Dave

I am also interested. Maybe especially how to append to a file.
It would be nice, to build a small quick-capture app in android which can be a share target for other apps as well

A quick capture app would be great. I was thinking of a web clipper extension for browsers.

So what you’re trying is more or less correct, but the content type for markdown is text/markdown. Authentication headers may be required depending on your setup.

I don’t have access to my laptop right now, but if you look at your browser’s network traffic page, after you edit a file you’ll see a PUT request happen. Look at the headers there or copy it as a curl and you should see what’s going on.

There’s no append operation at the moment.

Thanks for the reply Zef, I’ll look at the network traffic. Thanks for the effort you put into SilverBullet, it’s a great app!

Regarding authentication, another convenient option is using the SB_AUTH_TOKEN environment variable: Install/Configuration

When you configure that, you can authenticate using a simple Authorization: Bearer <token> header.

Thanks to the your look at the network traffic advice I got a PUT working. It works using the cookie for auth eg:

curl 'https://sb.burke.chat/Projects.md' \
  -X 'PUT' \
  -H 'content-type: text/markdown' \
  -H 'cookie: auth_sb_burke_chat=eyJh.........' \
  --data-raw $'[[Klipper & Mainsail on VM]]\n[[NHS Couch to 5k]]\n[[Note Taking Apps]]\n[[Sailing Holiday 2025]]\n[[VPS For Critical Services]]\n[[Silverbullet Backup]]\n[[Winter Break 2024]]\n[[Update Homebox]]\n[[Yuri]]\n[[Weather Station]]\n[[TEST15]]\n'   

But when I use the token I created in the environment variable it doesn’t work. Docker compose file:

services:
  silverbullet:
    image: zefhemel/silverbullet
    restart: unless-stopped
    environment:
    - SB_USER=admin:xxxxxxxx
    - SB_AUTH_TOKEN:j3e....
    volumes:
      - ./space:/space
    ports:
      - 3000:3000
  watchtower:
    image: containrrr/watchtower
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

and curl using the bearer token:

curl 'https://sb.burke.chat/Projects.md' \
  -X 'PUT' \
  -H 'content-type: text/markdown' \
  -H 'Authorization: Bearer j3e...' \
  --data-raw $'[[Klipper & Mainsail on VM]]\n[[NHS Couch to 5k]]\n[[Note Taking Apps]]\n[[Sailing Holiday 2025]]\n[[VPS For Critical Services]]\n[[Silverbullet Backup]]\n[[Winter Break 2024]]\n[[Update Homebox]]\n[[Yuri]]\n[[Weather Station]]\n[[TEST16]]\n'

Does the token in the environment variable need to be encrypted or a certain length? I just typed in some randon string. Thanks

Strange, have you properly recreated the containers to make sure the new environment variables propagated? Here’s what I just tried and it works:

I run my server via:

SB_USER=zef:zef SB_AUTH_TOKEN=1234 silverbullet ~/tmp

But this is equivalent to what you do with docker compose.

Then I curl:

curl -X PUT -H 'Authorization: Bearer 1234' http://localhost:3000/testzef.md -v --data "Sup"

And it accepts the request and writes the file (when I change 1234 to something else it fails, as it should).

Thanks for confirming I’m on the right track. When I updated the docker env variable I did a compose down and then a compose up assuming that would be enough. I’ll keep playing around with it tomorrow, thanks for the help so far.

1 Like

I’ve narrowed down the issue. I installed silverbullet via deno and ran the command that you successfully tested

SB_USER=zef:zef SB_AUTH_TOKEN=1234 silverbullet ~/tmp

and I could PUT without an issue. I then tried a https PUT via ngix proxy manager and it also worked

I noticed that when I run docker compose

services:
  silverbullet:
    image: zefhemel/silverbullet
    restart: unless-stopped
    environment:
    - SB_AUTH_TOKEN:1234
    - SB_USER=zef:zef
    volumes:
      - ./space:/space
    ports:
      - 3000:3000
  watchtower:
    image: containrrr/watchtower
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

the SB_AUTH_TOKEN wasn’t included in the env variables when I inspected docker

"Env": [
    "SB_USER=zef:zef",
    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
    "DENO_DIR=/deno-dir/",
    "DENO_INSTALL_ROOT=/usr/local",
    "DENO_VERSION=1.41.2",
    "TINI_VERSION=v0.19.0",
    "SB_HOSTNAME=0.0.0.0",
    "SB_FOLDER=/space"
],

Great I thought! I’ve cracked it! I then ran docker from the command line

docker run --restart unless-stopped -e SB_USER=zef:zef -e SB_AUTH_TOKEN:1234 -v ./space:/space -p 3000:3000 zefhemel/silverbullet

and the SB_AUTH_TOKEN is now included

"Env": [
    "SB_USER=admin:zef:zef",
    "SB_AUTH_TOKEN:1234",
    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
    "DENO_DIR=/deno-dir/",
    "DENO_INSTALL_ROOT=/usr/local",
    "DENO_VERSION=1.41.2",
    "TINI_VERSION=v0.19.0",
    "SB_HOSTNAME=0.0.0.0",
    "SB_FOLDER=/space"
],

But it still doesn’t work :frowning: I don’t know how docker works but could the SB_AUTH_TOKEN not be passed into silverbullet somehow? Thanks

I’m not positive, but the issue might be because you’re using : instead of =. If you switch SB_AUTH_TOKEN:1234 to SB_AUTH_TOKEN=1234, does it work?

1 Like

Thanks Justyns, you nailed it!

1 Like