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

AI-generated summary

The discussion revolves around the discrepancy between two API endpoints for retrieving user badges in Discourse: /users/username/activity/badges.json and /user-badges/username.json. kimardenmiller notes that the former only returns a subset of badges, while the latter returns all badges. justin confirms that the /user-badges/username.json endpoint is already functional but not yet integrated into the discourse_api gem. kimardenmiller seeks feedback on whether to replace the existing user_badges method in the gem to use the more comprehensive endpoint. blake supports this change, suggesting the existing method should be replaced if the only difference is the completeness of the badge data.

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?

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?

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:.