this post was submitted on 04 Jul 2023
5 points (100.0% liked)

Lemmy Support

4652 readers
1 users here now

Support / questions about Lemmy.

Matrix Space: #lemmy-space

founded 5 years ago
MODERATORS
 

I would like to be able to use the command line (curl) to get a list of communities I am currently subscribed to.

I know that there is a full-blown API, but it only briefly covers what it is possible with simple a curl request, and most of it seems to refer to an API that runs in javascript (which seems excessively complex for what I want to do?)

A simple curl request like this seems to work,

curl "https://mander.xyz/api/v3/community/list" | jq

But I wouldn't know how to make it list only communities that I subscribe to? Does anyone know more?

top 9 comments
sorted by: hot top controversial new old
[–] nachtigall@feddit.de 3 points 1 year ago (4 children)

For subscribed communities you have to add an auth parameter (that you can obtain by POST'ing {username_or_email: "your_name", password: "your_password"} to /user/login, then extracting the jwt from the response) and type_=Subscribed. A complete request would look like that:

curl "https://mander.xyz/api/v3/community/list?auth=verylongstring&type_=Subscribed" | jq

[–] test_account@lemmy.ml 3 points 1 year ago

While this is the correct syntax, in reality the API is broken and isn't returning communities (either filtered or sorted first) by their listingtype == "Subscribed"

[–] NeonWoofGenesis@lemmy.henlo.fi 2 points 1 year ago* (last edited 1 year ago) (1 children)

Rofl I don't know why someone downvoted you, this was nice information thanks.

I like to add that the keys must be wrapped in double quotes to be parsed as proper JSON.

# POST to login endpoint
curl -v --data '{"username_or_email": "username", "password": "password"}' --header 'Content-Type: application/json' https://example.com/api/v3/user/login
[–] nachtigall@feddit.de 1 points 1 year ago* (last edited 1 year ago)

You are totally right, seems like I forgot them ^^'

[–] notsofunnycomment@mander.xyz 1 points 1 year ago (1 children)

This works! Thanks.

If you're up for it, one last question: just running curl "https://mander.xyz/api/v3/community/list?auth=longstring&type_=Subscribed gives me only a few subscribed communities.

I can increase the number of subscribed communities that I get back, by adding &limit=.

curl "https://mander.xyz/api/v3/community/list?auth=longstring&type_=Subscribed&limit=50"

However, putting the limit too low I don't get all my subscribed communities, while putting the limit too high results in an error.

Is there a way to set limit to "max" or the limit to "nil" or something like that?

[–] notsofunnycomment@mander.xyz 2 points 1 year ago (1 children)

Wait, I see, the fetch limit is 50...

Any ideas how I could easily get all communities I subscribed to?

[–] notsofunnycomment@mander.xyz 2 points 1 year ago* (last edited 1 year ago)

Ok, I'll keep the monologue going: turns out I can loop through pages with that limit:

curl "https://mander.xyz/api/v3/community/list?auth=longstring&type_=Subscribed&limit=50&page=1

And then

curl "https://mander.xyz/api/v3/community/list?auth=longstring&type_=Subscribed&limit=50&page=2

Etc.

[–] PCChipsM922U@sh.itjust.works 1 points 1 year ago (1 children)

What if the account has 2FA?

[–] nachtigall@feddit.de 2 points 1 year ago* (last edited 1 year ago)

In that case add a totp_2fa_token field to the login struct which holds the top token. The rest remains the same.

load more comments
view more: next ›