# '/admin/users/{id}/log\_out.json' is not working

**URL:** https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185
**Category:** Development
**Tags:** rest-api
**Created:** [March 17, 2022, 3:19am UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185 "2022-03-17T03:19:33Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![bymong](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bymong/32/241482_2.png) [@bymong](https://meta.discourse.org/u/bymong)
#### Post date: [March 17, 2022, 3:19am UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/1 "2022-03-17T03:19:33Z")

</div>

> **[Discourse API Docs](https://docs.discourse.org/#operation/logOutUser)**

I trying to make a sample code for LogOut

My site dns is ‘[aaa.com](http://aaa.com)’, and User ID is ‘1’.  
I made url and send request like this.  
-post [AAA Sorry Page](https://aaa.com/admin/users/1/log_out.json)  
Also, I send header with api-key, api-Username.  
But I recived response to “Oops! That page doesn’t exist or is private.”

 ![image](https://global.discourse-cdn.com/meta/original/3X/5/f/5f8bf67cd1ddf6e233503d4e08ed9b4fe48feac8.png)

I trying to ‘CURL’, like this.  
But I got same result. (Oops! That page doesn’t exist or is private~~~ )

curl -X POST " [AAA Sorry Page](http://aaa.com/admin/users/1/log_out.json) "   
-H “Content-Type: multipart/form-data;”   
-H “Api-Key: secretStringTemp”   
-H “Api-Username: system”   
-F “id=1” \

Could you help me what am I wrong

---

<div class="post-metadata">

### Author: ![seanc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/seanc/32/302914_2.png) [@seanc](https://meta.discourse.org/u/seanc)
#### Post date: [April 17, 2023, 2:22pm UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/2 "2023-04-17T14:22:16Z")

</div>

Hey,  
Same issue here. Did you get anywhere with this?  
Cheers

---

<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: [April 17, 2023, 2:37pm UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/3 "2023-04-17T14:37:37Z")

</div>

I’m still able to log out users via the api. Here is the curl command I used:

```plaintext
curl -i -sS -X POST "http://localhost:4200/admin/users/1/log_out.json" \
-H "Content-Type: multipart/form-data" \
-H "Api-Key: 64b901d2357526d1b6e8c439fd0570f9c585073e6160ae18cc82b7ac358d4893" \
-H "Api-Username: blake.erickson" 

HTTP/1.1 200 OK

{"success":"OK"}

```

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/a/9/da9a3d702bd064f9849884690935e8ef9648c703.png)

If you are still having issues, can you share more info about your api request with us?

---

<div class="post-metadata">

### Author: ![seanc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/seanc/32/302914_2.png) [@seanc](https://meta.discourse.org/u/seanc)
#### Post date: [April 17, 2023, 2:15pm UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/4 "2023-04-17T14:15:16Z")

</div>

I’m stumped!

I can’t log a user out using the API endpoint `/admin/users/{USER_ID}/log_out.json`

I’m successfully retrieving the discourse `USER_ID` with the following: `/u/by-external/${user.id}.json`.

I’m also retrieving data by hitting other API endpoints so I’m happy with the API key and the mechanics around my request.

But when trying to send a post request…

```js
await axios.post(`${process.env.FORUM_URL}/admin/users/${UserID}/log_out.json`,{
  headers: {
    'Api-Key': process.env.DISCOURSE_API_KEY, 
    'Api-Username': process.env.DISCOURSE_API_USERNAME, 
  },
});

```

…I get a status 404 with the following return object:

```js
{
  errors: ['The requested URL or resource could not be found.'],
  error_type: 'not_found'
}

```

I managed to implement SSO without too much trouble. Any insight on why the logout might not be working would be great.

Cheers.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [April 17, 2023, 2:22pm UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/5 "2023-04-17T14:22:57Z")

</div>

This looks okay to me at first glance 🤔 . Does `UserID` hold a proper value?

---

<div class="post-metadata">

### Author: ![seanc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/seanc/32/302914_2.png) [@seanc](https://meta.discourse.org/u/seanc)
#### Post date: [April 17, 2023, 2:37pm UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/6 "2023-04-17T14:37:51Z")

</div>

Yes, in the test case it’s 1 (obtained from a call to `/u/by-external/${user.id}.json` ). Also tried hard-coding the value, just to double check…same result.

---

<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: [April 17, 2023, 2:55pm UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/8 "2023-04-17T14:55:25Z")

</div>

I’ve slipped over the posts from the other topic here to keep the discussion grouped together. 👍

Sorry if it’s a little out of sync. 🙂

---

<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: [April 17, 2023, 3:03pm UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/9 "2023-04-17T15:03:24Z")

</div>

One way I can replicate the 404 error message is to use an invalid user-id. Can you verify you can fetch the user by id first?

```plaintext
curl -i -sSL -X GET "http://localhost:4200/admin/users/1.json" \
-H "Api-Key: 64b901d2357526d1b6e8c439fd0570f9c585073e6160ae18cc82b7ac358d4893" \
-H "Api-Username: blake.erickson" 

HTTP/1.1 200 OK

{
  "id": 1,
  "username": "blake.erickson",
...

```

---

<div class="post-metadata">

### Author: ![seanc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/seanc/32/302914_2.png) [@seanc](https://meta.discourse.org/u/seanc)
#### Post date: [April 17, 2023, 3:29pm UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/10 "2023-04-17T15:29:12Z")

</div>

Ok, so I’ve confirmed I am retrieving a valid user\_id from Discourse, 1 in this case…

```plaintext
{
  "id":1,
  "username":"Sean",
...
}

```

Interestingly, when I send a cURL request to the `log_out` endpoint for user id 1…

```plaintext
curl -i -sS -X POST https://community.site.com/admin/users/1/log_out.json
-H "Content-Type: multipart/form-data" 
-H "Api-Key: my-api-key" 
-H "Api-Username: Sean" 

```

…I get a 200 response, suggesting that the user 1 (me) should be logged out of the forum, but when I check, I haven’t actually been logged out - that’s issue one.

Second problem is that sending the same request from my app backend using axios (detailed above) results in a 404…very strange.

**Edit:**  
_Issue one is not an issue - the cURL request is successfully logging me out - just need to work out now why the axios post request is giving me 404._

---

<div class="post-metadata">

### Author: ![seanc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/seanc/32/302914_2.png) [@seanc](https://meta.discourse.org/u/seanc)
#### Post date: [April 17, 2023, 4:01pm UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/11 "2023-04-17T16:01:05Z")

</div>

Ok - mystery solved 🙄

Turns out my axios request wasn’t formatted correctly! Since I’m not sending any body in the post request, I should have passed an empty object with the request.

Thanks for the steer re. curl requests @blake - that’s ultimately what unlocked it for me. 👍

---

<div class="post-metadata">

### Author: ![Siddharth\_Pradhan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/siddharth_pradhan/32/299763_2.png) [@Siddharth\_Pradhan](https://meta.discourse.org/u/Siddharth_Pradhan)
#### Post date: [May 18, 2023, 9:09am UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/12 "2023-05-18T09:09:48Z")

</div>

Hi Sean,

Can you please share the log\_out.json code since I am working on a similar request

---

<div class="post-metadata">

### Author: ![Atchuth\_Reddy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/atchuth_reddy/32/321802_2.png) [@Atchuth\_Reddy](https://meta.discourse.org/u/Atchuth_Reddy)
#### Post date: [September 6, 2023, 9:40am UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/14 "2023-09-06T09:40:48Z")

</div>

I have tried logging out forum with post api ‘admin/users/{user\_id}/log\_out.json’ but it returns with Oops! That page doesn’t exist or is private.  
I have provided api\_key and api-username with in headers. Does anyone faced same issue

---

<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: [September 6, 2023, 9:56am UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/15 "2023-09-06T09:56:35Z")

</div>

Would you need to use an admin API key for that endpoint?

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [September 6, 2023, 10:34am UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/16 "2023-09-06T10:34:50Z")

</div>

I successfully logged myself out using the API by sending a POST request to `/admin/users/1/log_out.json`.

Empty body, headers containing an admin Api-Username and an Api-Key with either global scope or granular scope with log-out capability checked.

---

<div class="post-metadata">

### Author: ![Atchuth\_Reddy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/atchuth_reddy/32/321802_2.png) [@Atchuth\_Reddy](https://meta.discourse.org/u/Atchuth_Reddy)
#### Post date: [September 6, 2023, 12:44pm UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/17 "2023-09-06T12:44:39Z")

</div>

Yes, I have used admin API Key

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [September 6, 2023, 1:08pm UTC](https://meta.discourse.org/t/admin-users-id-log-out-json-is-not-working/221185/18 "2023-09-06T13:08:39Z")

</div>

How or which software or programming language did you make the API call with? Can you copy-paste your code here?
