# API / anonymize or delete

**URL:** https://meta.discourse.org/t/api-anonymize-or-delete/158704
**Category:** Development
**Tags:** rest-api
**Created:** [July 24, 2020, 4:20pm UTC](https://meta.discourse.org/t/api-anonymize-or-delete/158704 "2020-07-24T16:20:18Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![aahoughton](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aahoughton/32/187936_2.png) [@aahoughton](https://meta.discourse.org/u/aahoughton)
#### Post date: [July 24, 2020, 4:20pm UTC](https://meta.discourse.org/t/api-anonymize-or-delete/158704/1 "2020-07-24T16:20:18Z")

</div>

'lo. We’re using hosted discourse with OAuth. We suddenly realized that when we process deletions, we’re neglecting to delete from our discourse instance.

I’d _like_ to be able to anonymize an account, OR delete an account programmatically using the API – but I don’t see an easy way to do that, given that I don’t know what the discourse account ID is.

Am I missing something obvious? Any suggestions?

Thanks,

Andrew

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [July 24, 2020, 5:21pm UTC](https://meta.discourse.org/t/api-anonymize-or-delete/158704/2 "2020-07-24T17:21:47Z")

</div>

> [@aahoughton](#):
>
> I’d _like_ to be able to anonymize an account, OR delete an account programmatically using the API – but I don’t see an easy way to do that, given that I don’t know what the discourse account ID is.

Do you know if email addresses match between your OAuth identity provider and Discourse? If they do, you could get the Discourse user based on their email address by making an authenticated API request to `/admin/users/list/all.json?email=<users_email_address>`. For example:

```plaintext
curl -X GET "http://localhost:3000/admin/users/list/all.json?email=bob@example.com" \
-H "Api-Key: $api_key" \
-H "Api-Username: system"

```

---

<div class="post-metadata">

### Author: ![aahoughton](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aahoughton/32/187936_2.png) [@aahoughton](https://meta.discourse.org/u/aahoughton)
#### Post date: [July 24, 2020, 5:25pm UTC](https://meta.discourse.org/t/api-anonymize-or-delete/158704/3 "2020-07-24T17:25:13Z")

</div>

They should match, thank you – that was the call I was missing. Verifying.

---

<div class="post-metadata">

### Author: ![jezra](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jezra/32/105986_2.png) [@jezra](https://meta.discourse.org/u/jezra)
#### Post date: [April 26, 2021, 7:35pm UTC](https://meta.discourse.org/t/api-anonymize-or-delete/158704/4 "2021-04-26T19:35:36Z")

</div>

I am also interested in using an api call to anonymize a user. What is the API endpoint you are using to anonymize a user?

---

<div class="post-metadata">

### Author: ![weallwegot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/weallwegot/32/124753_2.png) [@weallwegot](https://meta.discourse.org/u/weallwegot)
#### Post date: [April 27, 2021, 2:20am UTC](https://meta.discourse.org/t/api-anonymize-or-delete/158704/5 "2021-04-27T02:20:57Z")

</div>

The API endpoint for anonymizing:

**HTTP Method:** PUT  
**Endpoint:** [https://example-community.dev/admin/users/{id}/anonymize](https://example-community.dev/admin/users/%7Bid%7D/anonymize)

> [@Anonymize user - blank response from API on attempt?](https://meta.discourse.org/t/anonymize-user-blank-response-from-api-on-attempt/79144):
>
> Hi folks, I’m trying to hit the endpoint to anonymize a user in Discourse; I’ve got single sign-on between WordPress and Discourse set up, and when the user deletes their account on WordPress I want to anonymize them in Discourse. The endpoint is /admin/users/{id}/anonymize: put: description: | Anonymize a user tags: - Admin parameters: - name: id in: path required: true type: integer responses: '200': description: succesfully anonymized user …

* * *

you can use the call shown above to get the `{id}` value if you already know the email of the user you want to anonymize

> [@simon](#):
>
> ```plaintext
> curl -X GET "http://localhost:3000/admin/users/list/all.json?email=bob@example.com" \
> -H "Api-Key: $api_key" \
> -H "Api-Username: system"
> 
> ```

---

<div class="post-metadata">

### Author: ![sarahann](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sarahann/32/96703_2.png) [@sarahann](https://meta.discourse.org/u/sarahann)
#### Post date: [July 27, 2021, 2:14am UTC](https://meta.discourse.org/t/api-anonymize-or-delete/158704/6 "2021-07-27T02:14:58Z")

</div>

Was the `/anonymize` endpoint removed form the API docs?

I was looking here:

> **[Discourse API Docs](https://docs.discourse.org/#tag/Admin/paths/~1admin~1users~1%7Bid%7D.json/get)**

Under `users` as well as `admin`.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [July 28, 2021, 1:03am UTC](https://meta.discourse.org/t/api-anonymize-or-delete/158704/7 "2021-07-28T01:03:56Z")

</div>

It might not have been added to the api docs yet, I’ll make sure it gets documented soon.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [July 29, 2021, 11:53pm UTC](https://meta.discourse.org/t/api-anonymize-or-delete/158704/8 "2021-07-29T23:53:37Z")

</div>

@sarahann the [`/anonymize`](https://docs.discourse.org/#tag/Admin/paths/~1admin~1users~1%7Bid%7D~1anonymize.json/put) route has been added to the api docs.

---

<div class="post-metadata">

### Author: ![sarahann](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sarahann/32/96703_2.png) [@sarahann](https://meta.discourse.org/u/sarahann)
#### Post date: [August 19, 2021, 9:17pm UTC](https://meta.discourse.org/t/api-anonymize-or-delete/158704/9 "2021-08-19T21:17:28Z")

</div>

Phew! Scared me for a sec 😛

Thanks for the speedy turnaround on this!
