I got it working in shell as well:
#!/bin/bash
read -p "Username: " user
read -p "Password: " -s pass
read -p "TOTP: " totp
res=$(curl \
--request POST \
--url "https://feddit.ch/api/v3/user/login" \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{"username_or_email":"'$user'","password":"'$pass'","totp_2fa_token":"'$totp'"}')
jwt=$(echo $res | sed -re 's/^.*"jwt":"([^"]*)".*$/\1/')
curl \
--request GET \
--url "https://feddit.ch/api/v3/user/export_settings" \
--header 'accept: application/json' \
--cookie "jwt=$jwt" \
-o "export.json"
I’d recommend echoing $res and $jwt before processing them further
Edit: if you don’t have TOTP enabled, don’t forget to remove it from the request
Docs: https://lemmy.readme.io/reference/post_user-login
Edit 2: added spacing
See: https://feddit.ch/comment/5778007