Getting the logged in user's username from JSON API

Hi :blush:

I’ve been having some fun building a little personal web client for Micro.blog using the JSON API following the documentation here.

I have it so I can authenticate a user and get back a bearer token and can use that to call various endpoints successfully. I can even get usernames for post authors under the _microblog object. But what I can’t seem to find anywhere is the username of the logged in user. The response passed back from the https://micro.blog/indieauth/token doesn’t seem to have it… I was expecting something like heyloura (my Micro.blog username) but I just got my profile name:

{
  scope: "create",
  me: "https://heyloura.micro.blog/",
  profile: {
    name: "Loura",
    url: "https://heyloura.com",
    photo: "https://avatars.micro.blog/avatars/2022/144491.jpg"
  },
  token_type: "Bearer",
  access_token: " ... "
}

The endpoint /posts/timeline doesn’t seem to have it either. Any pointer to where I can find it? I want to build out some functionality that uses endpoints that require a username (like /users/pins/[username] and /users/following/[username]).

Thanks!

This sounds great! You’re right, we really should include the username in more places, especially the IndieAuth response. In the meantime, you can make a separate HTTP POST to /account/verify and pass a token parameter, and it will return some more information about the user including the username.

Let me know if that doesn’t work.

Awesome! That worked like a charm.

Thanks Manton!

I was thinking about this a little more and plan to add nickname as a field in the profile response. This seems consistent with parts of Micropub (like user search) and Microformats. It’ll roll out next week.

1 Like