#!/bin/bash

# Basic login script for Lemmy API

# CHANGE THESE VALUES
my_instance=""			# e.g. https://feddit.nl
my_username=""			# e.g. freamon
my_password=""			# e.g. hunter2

########################################################

# Lemmy API version
API="api/v3"

########################################################

# Turn off history substitution (avoid errors with ! usage)
set +H

########################################################

# Login
login() {
	end_point="user/login"
	json_data="{\"username_or_email\":\"$my_username\",\"password\":\"$my_password\"}"

	url="$my_instance/$API/$end_point"

	curl -H "Content-Type: application/json" -d "$json_data" "$url"
}

login

# Make note of "jwt" from reply

This’ll reply with JSON data, that includes a value for “jwt”, to be used in other scripts that require you to be logged in.

Personally, I’d use the ‘jq’ program to de-serialize the JSON data, but I thought I’d keep the script simple for now

You are viewing a single thread.
View all comments View context
2 points

Ooops. I tested it before I posted, and the reason it worked is because it turns out that authentication isn’t needed for that query.

I’ve edited the comment now, and there only being one part means that there’s no need for an ampersand, so there’s no probs with special characters.

permalink
report
parent
reply
2 points

That got me there. I just made my first scripted post. I’ll take it from here with queuing my content. Thanks again!

permalink
report
parent
reply

Linux Troubleshooting and scripts

!linuxscripts@lemmy.zip

Create post

this is a community for sharing your scripts that help when working with Linux as well a general troubleshooting.

Rules

  • Absolutely NO NSFW posts. break this rule and you will be removed from this community. NO EXCEPTIONS!

  • Only post scripts that help yourself and others. All scripts will be tested on my machine personally, any malicious scripts will be removed immediately.

  • This community is for the benefit of other Linux users. no bigotry, hate, nudes, malicious scripts or politics allowed.

Feel free to ask any kind of support questions, as we grow more succinct answers will be available. Let’s make this community grow.

We are important to one another, not only in the linux world but also in the fediverse as a whole. Feel free to reach out to me with questions or concerns, as we grow bigger I will look into adding mods. (This section will be updated as needed.)

Community stats

  • 3

    Monthly active users

  • 21

    Posts

  • 49

    Comments

Community moderators