0

Iam trying to delete a subscriber user using rest api admin api account. However, the api seems to require specifying reassign user id however i dont want to reassign.

Iam using the python requests module, and I'am issuing a basic delete request as follows:

import base64
import requests
import json

from Load_Credentials import user,password

userurl='https://mywebsite.com/wp-json/wp/v2/users'
credentials = user + ':' + password
token = base64.b64encode(credentials.encode())
header = {'Authorization': 'Basic ' + token.decode('utf-8'),'Content-Type': 'application/json','User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}

userid=139
deleteurl='https://mywebsite.com/wp-json/wp/v2/users/139?force=True'
response = requests.delete(deleteurl, headers=header)

print(response.json())

This is the response Iam getting:

'code': 'rest_missing_callback_param', 'message': 'Missing parameter(s): reassign', 'data': {'status': 400, 'params': ['reassign']}}

I understand that the request requires the reassign parameter, however, i dont want to reassign, I want to delete without reassigning. I tried reassign=false but also did not work:

deleteurl=https://myywebsite.com/wp-json/wp/v2/users/139?reassign=false?force=True

heres the response:

{'code': 'rest_invalid_param', 'message': 'Invalid parameter(s): reassign', 'data': {'status': 400, 'params': {'reassign': 'Invalid user parameter(s).'}, 'details': {'reassign': {'code': 'rest_invalid_param', 'message': 'Invalid user parameter(s).', 'data': {'status': 400}}}}}

Any suggestions?

8
  • Have you tried reassign=0? Feb 18, 2022 at 8:36
  • Yes, i tried but didnt work. Heres the url and response. URL=mywebsite.com/wp-json/wp/v2/users/139?reassign=0?force=True. Response= {'code': 'rest_invalid_param', 'message': 'Invalid parameter(s): reassign', 'data': {'status': 400, 'params': {'reassign': 'Invalid user parameter(s).'}, 'details': {'reassign': {'code': 'rest_invalid_param', 'message': 'Invalid user parameter(s).', 'data': {'status': 400}}}}}
    – The Oracle
    Feb 18, 2022 at 8:37
  • @TheOracle your query string is invalid - it has two ? as in ?reassign=0?force=True - or was that just a typo? If not, then try with ?reassign=0&force=true..?
    – Sally CJ
    Feb 18, 2022 at 9:25
  • 1
    And actually, why don't you want to assign the content to other user (like an administrator) 🤔, or just use the reassign=0 to assign the user's content to nobody..? (but yes, for example the user's posts would have post_author set to 0)
    – Sally CJ
    Feb 18, 2022 at 11:34
  • 1
    good idea, i can actually use reassign =0 , this was also suggested by Jacob however did not work previously(probably due to the extra ? that was added before, now corrected). Thanks
    – The Oracle
    Feb 18, 2022 at 11:40

2 Answers 2

1

Looking at the code for the users endpoint, I don't think this is possible. I also dug up this ticket on the issue which links to this ticket that confirms that this is a deliberate limitation.

The explanation is that WordPress does not give the option to delete users without either deleting their content or reassigning it to another author. This is because WordPress does not support content without an author. If this parameter were optional then it would be possible to leave behind content without an author.

It looks like there was talk about allowing deletion of a user's content by passing a false value, but that does not appear to have been implemented.

0

Reading this post I found an update: /wp-json/wp/v2/users/25?reassign=false&force=true

The parameters to add is equal to trashing the posts.

reassign=false force=true

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.