'/admin/users/{id}/log_out.json' is not working

https://docs.discourse.org/#operation/logOutUser

I trying to make a sample code for LogOut

My site dns is ‘aaa.com’, and User ID is ‘1’.
I made url and send request like this.
-post AAA Sorry Page
Also, I send header with api-key, api-Username.
But I recived response to “Oops! That page doesn’t exist or is private.”

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 "
-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

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

1 Like

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

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"}

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

1 Like

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…

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:

{
  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.

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

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.

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

Sorry if it’s a little out of sync. :slight_smile:

3 Likes

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?

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",
...
1 Like

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

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

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

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.

1 Like

Ok - mystery solved :roll_eyes:

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. :+1:

3 Likes

Hi Sean,

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

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

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

1 Like

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.

1 Like

Yes, I have used admin API Key

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