Generate the JWT (JSON web token) for Shaarli API authentication using Python and Javascript

Official documentation of Shaarli only gives a PHP example, but I’m more of a Python kind of guy.

This is how to generate a JSON web token (JWT) using some Python or Javascript code.


Keep in ming this uses PyJWT (pip install PyJWT) and not jwt.

Replace SHAARLI_API_SECRET accordingly:

import time
import jwt
now = int(time.time())
payload = { "iat" : now }
SHAARLI_API_SECRET = "your shaarli REST API Secret"
token = jwt.encode(payload, SHAARLI_API_SECRET, algorithm = SHAARLI_HASH_ALGORITHM)



Here’s an example with javascript (npm install jsonwebtoken)

let jwt = require('jsonwebtoken');
let now = Math.floor( / 1000)

const shaarli_api_secret = 'your shaarli REST API Secret"';
const payload = {
  "iat": now

let token = jwt.sign(payload, shaarli_api_secret, { algorithm: 'HS512'});


Test your JWT

You can now use the JWT (replace <your-newly-obtained-jwt-token> with the output of previous script):

curl --request GET \
  --url '' \
  --header 'Authorization: Bearer <your-newly-obtained-jwt>'


[{"id":4947,"url":"https:\/\/\/title\/NetworkManager#Configuring_MAC_address_randomization","shorturl":"4X0sQg","title":"NetworkManager - ArchWiki","description":"configure MAC address randomization using NetworkManager","tags":["linux","mac"],"private":false,"created":"2022-12-16T18:10:33+01:00","updated":"2022-12-18T23:00:07+01:00"}]

Thanks for reading this post!

Did you find an issue in this article?

- click on the following Github link
- log into Github with your account
- click on the line number containing the error
- click on the "..." button
- choose "Reference in new issue"
- add a title and your comment
- click "Submit new issue"

Your feedback is much appreciated! πŸ€œπŸΌπŸ€›πŸΌ

You can also drop me a line below!