How to get `person_id` from currently logged in user in API?

3 years ago by Charlie Fish to c/lemmy

After getting a LoginResponse from the Lemmy API, it returns an auth JWT token.

I'm trying to figure out how I can get that users person_id or username so I can make a GetPersonDetails request for the currently logged in user.

Any ideas on how to do this?

picoblaanket 2 points 3 years ago

Successful Login automatically initiates a GetSite operation, which contains person_id:

op.data.my_user.local_user_view.local_user.person_id

and username:

op.data.my_user.local_user_view.person.name

Maybe that will do it.

path: 0 332778, hotness: undefined, score: 2, children: 0
Slated 2 points 3 years ago

You’ll want to save the JWT and then use it as the auth parameter for GetPersonDetails

path: 0 348244, hotness: undefined, score: 2, children: 2
fishcharlie 0 points 3 years ago

This doesn't work either. Only passing in an auth parameter into GetPersonDetails is not valid and returns an error.

path: 0 348244 351346, hotness: undefined, score: 0, children: 1
Slated 1 point 3 years ago

Oh strange I would assume you would want to either include the id or the username, whatever the documentation asks for. You can also always just use the GetSite endpoint and GetSiteResponse.my_user

path: 0 348244 351346 351347, hotness: undefined, score: 1, children: 0
plisken -1 points 3 years ago

I havent tried, but usually a JWT contains some sort of user ID

path: 0 308428, hotness: undefined, score: -1, children: 0
lemmy
lemmy

@lemmy.ml

login for more options
14708
1352
63

Everything about Lemmy; bugs, gripes, praises, and advocacy.

For discussion about the lemmy.ml instance, go to !meta@lemmy.ml.

go to feed...