API - How to revoke badge from a user

Hi guys,

I’ve been trying to reverse engineer the revoke badge API endpoint, but I can’t figure out how its done. When i’m looking at the XHR requests on the inspector, I can’t figure out how the API knows what user/badge I want deleted. I’m not super experienced with hacking APIs, so I’m not sure if I’m missing some additional data, but all the parts of the API i’ve reverse engineered had some kind of form data attached to it.

This is what I’m seeing:

As far as I can see it’s a DELETE to the url http://testforum.daohub.org/user_badges/36, different badges have different numbers, but I’m not sure how it knows which user to delete it from. If I add and remove the same badge, the number is different the second time round so it doesn’t seem to be using the badgeID for it either.

Any help would be appreciated.

Thanks.

1 Like

This took a moment to research, but it’s not that hard actually:

  • GET to /user-badges/<username>.json
  • In the result, inspect user_badges and find the entry you want to delete. You can identify the badge by its badge_id, which will be defined in the badges property of the answer.
  • Look at the id property of the entry you want to delete, and DELETE /user_badges/<id>.

Interestingly, the response to /user-badges/<username>.json also contains a few badges the have not been granted to this user – maybe a :discourse: team member can explain why :slight_smile:

4 Likes

Hey Felix,

Thanks for the reply. I had a look at a particular user, but I found the user badges array you were talking about. However no matter what I do, it only seems to return 3 badges even if my user has say 7 badges. I need to be able to remove one particular badge from the user, but I’m not sure how to target that particular badge if I can’t get the ‘id’ of the badge. I can see clearly that a user has lots of badges, but if there’s a chance I can’t actually see the badges they own, I can’t get that particular id to remove it.

Seems like there are two ids, one of the id of the actual badge that was granted and an id for the type of badge it is. Anyone know how to remove a badge of a user when you don’t know the actual id of the badge (not the type of badge) or just using the type of badge + username?

Are you 100% certain that the corresponding user has 7 badges appear on /admin/users/<id>/<name>/badges, but only 3 on /user-badges/<username>.json in the property user_badges? Are you sure you are looking at this property, not another one?

1 Like

Sorry felix, you’re right, I was looking at the user json not the user/badge json. Thanks for the clarification.

2 Likes

This topic was automatically closed after 2919 days. New replies are no longer allowed.