# API - 如何从用户吊销徽章

**URL:** https://meta.discourse.org/t/api-how-to-revoke-badge-from-a-user/45560
**Category:** Support
**Created:** [2016年六月11日 07:13 UTC](https://meta.discourse.org/t/api-how-to-revoke-badge-from-a-user/45560 "2016-06-11T07:13:24Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jefflau](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jefflau/32/121720_2.png) [@jefflau](https://meta.discourse.org/u/jefflau)
#### Post date: [2016年六月11日 07:13 UTC](https://meta.discourse.org/t/api-how-to-revoke-badge-from-a-user/45560/1 "2016-06-11T07:13:24Z")

</div>

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:

 ![](https://global.discourse-cdn.com/meta/original/3X/7/c/7c4b126fee5cdbc3361645049a8687183a5eef73.png)

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.

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [2016年六月11日 11:06 UTC](https://meta.discourse.org/t/api-how-to-revoke-badge-from-a-user/45560/2 "2016-06-11T11:06:57Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![jefflau](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jefflau/32/121720_2.png) [@jefflau](https://meta.discourse.org/u/jefflau)
#### Post date: [2016年六月13日 11:17 UTC](https://meta.discourse.org/t/api-how-to-revoke-badge-from-a-user/45560/3 "2016-06-13T11:17:16Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [2016年六月13日 12:22 UTC](https://meta.discourse.org/t/api-how-to-revoke-badge-from-a-user/45560/4 "2016-06-13T12:22:27Z")

</div>

> [@jefflau](#):
>
> However no matter what I do, it only seems to return 3 badges even if my user has say 7 badges.

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?

---

<div class="post-metadata">

### Author: ![jefflau](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jefflau/32/121720_2.png) [@jefflau](https://meta.discourse.org/u/jefflau)
#### Post date: [2016年六月13日 18:29 UTC](https://meta.discourse.org/t/api-how-to-revoke-badge-from-a-user/45560/5 "2016-06-13T18:29:35Z")

</div>

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

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2024年六月8日 12:45 UTC](https://meta.discourse.org/t/api-how-to-revoke-badge-from-a-user/45560/6 "2024-06-08T12:45:37Z")

</div>

该主题已在 2919 天后自动关闭。不再允许回复。
