question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get a 405 trying to delete a user using the API

See original GitHub issue

Describe the bug

The command to delete a user does not seem to be working.

To Reproduce

I followed the example in https://github.com/keycloak/keycloak-nodejs-admin-client/blob/master/test/users.spec.ts

  let user = await kcAdminClient.users.findOne({email})
  // Confirmed this is working and `user` is what I expect
  await kcAdminClient.users.del({
     id: user.id,
   });

I expect it to quietly delete the user. Instead I get an exception thrown:

    status: 405,
    statusText: 'Method Not Allowed',
    ...
    data: {
      error: 'RESTEASY003650: No resource method found for DELETE, return 405 with Allow header'
    }

I’ve logged into the admin console, found the user and deleted them there and it works; so I think the eliminates any firewalls or server settings.

In the browser network tab I can see a DELETE request was sent, and the headers look to match what I see in the nodejs exception. One difference is that the exception doesn’t show the user ID in the URL (so I assume it is in body data?).

Enviroment (please complete the following information):

  • OS: Ubuntu
  • Keycloak Version: 15.0.1
  • NodeJS 16.4.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DarrenCookcommented, Sep 12, 2022

Thanks @armujahid: that turned out to be the problem for me too. (I was just forced to revisit this!)

I think the underlying problem comes down to the surprising behaviour of findOne() described here: https://github.com/keycloak/keycloak-nodejs-admin-client/issues/461#issuecomment-1106365661

I.e. if you search on id as shown in the spec.ts document, it returns a user object, and if you search on anything else, such as email, it returns an array of user objects.

This just needs to be documented clearly somewhere. Perhaps also add a second unit test showing a delete by a field other than id; this is behaviour that needs testing. A simple clone of that user.del unit test, and swapping id for email should do it?

0reactions
jonkoopscommented, Sep 12, 2022

Feel free to open up a PR for adding another test, that’s always appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebAPI Delete not working - 405 Method Not Allowed
This issue is mainly related to WebDAV extension module on IIS server. this happened while Using Post OR delete action. Please try below...
Read more >
Delete User : 405 method not Allowed - HubSpot Community
Hi. I'm using API for insert / update my users list (batch) with my hapikey. But I've an error when I want to...
Read more >
Getting Error 405 on Delete REST API when running Azure ...
The Post APIs works. So, I can do a POST (to create a user) but when I do a Delete (to delete that...
Read more >
DELETE User response: 405 Method Not Allowed
EDIT: To be very clear the error is the response 405 “Method Not Allowed” I've checked the app permissions and roles, all seem...
Read more >
405 error when trying to delete environment from REST API
I'm trying to delete an Environment using the REST API (through PowerShell Invoke-RESTMethod) but receiving “error 405 method not allowed”.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found