API / anonymize or delete

'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

4 Likes

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:

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

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

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?

The API endpoint for anonymizing:

HTTP Method: PUT
Endpoint: https://example-community.dev/admin/users/{id}/anonymize


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

7 Likes

Was the /anonymize endpoint removed form the API docs?

I was looking here:
https://docs.discourse.org/#tag/Admin/paths/~1admin~1users~1{id}.json/get

Under users as well as admin.

2 Likes

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

3 Likes

@sarahann the /anonymize route has been added to the api docs.

3 Likes

Phew! Scared me for a sec :stuck_out_tongue:

Thanks for the speedy turnaround on this!

1 Like