# How to logout user by api

**URL:** https://meta.discourse.org/t/how-to-logout-user-by-api/386607
**Category:** Support
**Tags:** rest-api
**Created:** [October 24, 2025, 7:07am UTC](https://meta.discourse.org/t/how-to-logout-user-by-api/386607 "2025-10-24T07:07:29Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![adopilot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adopilot/32/105040_2.png) [@adopilot](https://meta.discourse.org/u/adopilot)
#### Post date: [October 24, 2025, 7:07am UTC](https://meta.discourse.org/t/how-to-logout-user-by-api/386607/1 "2025-10-24T07:07:29Z")

</div>

For while I am trying to logout user by api, but without success,

I did read [SSO Logout via Master API Key isn't working - #2 by simon](https://meta.discourse.org/t/sso-logout-via-master-api-key-isnt-working/56485/2)

My httpclient has set username and api key inside headers, and it works for other stuff e.g. post get user by external id or other.

Do I need to send api-key and api-username in body also.

My users are logged in by sso, when I logout user from admin page on discource it works.

Here is part of code how do I trying to call it

`var formData = new FormUrlEncodedContent(new`  
`{`  
`new KeyValuePair<string, string>(“username_or_email”, user.user.username)`  
`});`  
`var response = await _httpClient.PostAsync($“/admin/users/{user.user.id}/log_out”, formData);`  
`var content = await response.Content.ReadAsStringAsync();`

Response returns 200 code but content are web page not {Succes: “OK” }

---

_[View the full topic](https://meta.discourse.org/t/how-to-logout-user-by-api/386607)._
