API user_badges /users/username/activity/badges.json API vs. /user-badges/username.json

In the API we see:

  def user_badges(username)
    response = get("/users/#{username}/activity/badges.json")
    response.body['badges']
  end

But that does not get all the user’s badges. From Discourse>user>badges this call is made:

user-badges/username.json

which does give all the badges.

I need the second one. Add it to the API and do a PR? What should I call it?

1 Like

You can already hit this api endpoint at https://<sitename>/user-badges/<username>.json and it returns the full list of badges. Are you looking for something else?

1 Like

I’m speaking about discourse_API code. Don’t see it searching the code.

Unless I get other feedback, my sense is to replace the existing API method

  def user_badges(username)
    response = get("/users/#{username}/activity/badges.json")
    response.body['badges']
  end

with

  def user_badges(username)
    response = get("/user-badges/#{username}.json")
    response.body['badges']
  end

Comments?

If the only difference is that the latter one actually returns all the badges, I’m okay with replacing the existing method :slight_smile:.

3 Likes