Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Lemmy API: how to get list of followed/subscribed communities.
Context
Using the lemmy API, I'm trying to get a list of sublemmies (lemmy communities) that a user is following.
Reading the documentation, I using the /site
endpoint, I should be able to get a response containing a my_user
property.
However, when I query it, the response never contains the my_user
property. I've tried querying with and without sending the auth
property.
I couldn't find any documentation on when the optional my_user
property is returned. I'm assuming it required authentication.
I've tried querying using rust, insomnia and curl. Here are some of the curl queries (without real credentials of course):
Getting JWT token
Query
curl \
-H "Content-Type: application/json" \
-X POST \
-d '{
"username_or_email": "<username>",
"password": "<password>"
}' https://lemmy.ml/api/v3/user/login
Response
{"jwt":"<redacted>","registration_created":false,"verify_email_sent":false}
Using jq
to list top level keys from the response:
Query
curl \
-H "Content-Type: application/json" \
-X GET \
-d '{
"auth": "<JWT token generated via the /login endpoint>"
}' \
https://lemmy.ml/api/v3/site\
| jq 'keys'
Response (parsed by jq
)
Notice this doesn't include any my_user
property.
[
"admins",
"all_languages",
"custom_emojis",
"discussion_languages",
"site_view",
"taglines",
"version"
]
1 answer
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
elvis_depresley |
Thread: Works for me I didn't realise the auth was passed in as an URL parameter. This works for me, thank you! |
Jul 29, 2023 at 13:13 |
You are correct, my_user
is only returned when you supply the auth
parameter.
It looks like you're getting the JWT with no issues, based on your response to /api/v3/user/login
, but you must be passing the auth
parameter incorrectly if you're not getting a my_user
object in the response to /api/v3/site
.
Try passing it as a query parameter instead of a body parameter:
0 comment threads