PATCH on user to change the user name works fine.
But to change password and email it requires to specify current_password.
I tried to get help on how to pass this value but no response . So I read user module related code tried with "current_pass"
But it fails with 500. Screen shot attached.

PATCH on user

CommentFileSizeAuthor
PATCH on USER.png56.72 KBvivekvpandya
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vivekvpandya created an issue. See original summary.

cilefen’s picture

The issue summary needs a rewrite to be more understandable to contributors. I do not understand what this sentence means: "But to change password an email it requires to specify current_password."

Also, there is a mention of a patch, but not reference to an issue number.

cilefen’s picture

Issue tags: +Needs title update

The issue needs a more descriptive title.

vivekvpandya’s picture

Priority: Normal » Minor
vivekvpandya’s picture

@cilefen

It is about PATCH request on /user via REST full web service to update user details.
I want to change email address and password from my REST client talking to Drupal 8 backend ( All necessary permissions and setup has been done )
So If I make a PATCH request with following JSON

{"_links":{"type":{"href":"http://localhost/dr8b14/rest/type/user/user"}}, 
 "mail":[
   {"value":"vivek@gmail.com"}
 ]
}

It gives 422 Unprocessable Entity

{
"error": "Unprocessable Entity: validation failed.\nmail: Your current password is missing or incorrect; it's required to change the Email.\n"
}

So to I tried with

{"_links":{"type":{"href":"http://localhost/dr8b14/rest/type/user/user"}}, 
 "mail":[
   {"value":"vivek@gmail.com"}
 ],
 "current_pass":[{
   "value":"pasword here"
 }]
}

Then it gives 500.
So how do I specify current password so that I can change my email ?
Actually this is not issue regarding REST.
I inspect the error logs and I found this

InvalidArgumentException: Field current_pass is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 474 of /Applications/XAMPP/xamppfiles/htdocs/dr8b14/core/lib/Drupal/Core/Entity/ContentEntityBase.php).

So actually current_pass is not correct way to specify current password.
But this message is not getting propagated to REST client . I think it should not give 500.

cilefen’s picture

Issue summary: View changes

Oh a PATCH request! Sorry, I misunderstood.

cilefen’s picture

Title: PATCH on user not working properly » REST PATCH verb requires a password but Drupal does not communicate that back to the client
Issue tags: -Needs title update
cilefen’s picture

Priority: Minor » Normal
marthinal’s picture

Hi guys,

If you want to change your pass and mail then you need something like this:

 {
"_links":
{"type":{"href":"http://d8/rest/type/user/user"}},
"mail":[{"value":"marthinal@drupalisawesome.com"}],
"pass":[{"existing":"existingSecretPass", "value": "myNewSuperSecretPass"}]
}
marthinal’s picture

Status: Active » Needs review

Let me know if it works and probably we can close the issue.

cilefen’s picture

@marthinal Is this something that needs documenting somewhere?

marthinal’s picture

@cilefen Well I think we could add this info to the REST doc. It will be really helpful :) I can do it later today.

vivekvpandya’s picture

@marthinal

Thanks !
It worked .

vivekvpandya’s picture

@marthinal and @cilefen I think the error reporting to the client side can be improved because in my previous attempt it just got crashed with 500.
And Is there any plan to make a document for REST module API for Drupal 8 ? It would be better if we make something similar to document available for Twitter's REST API.
Please let me know if I can help in that .

marthinal’s picture

Added doc about it.
[#2558697]

@vivekvpandya About internal error 500... yes, I think it should be 400 (Bad request) because your request is not correct. When creating a new user from anonymous and adding a field that does not exist, I receive a 500 but the user is created as expected. I need to investigate a little bit more and maybe create a new issue about it. Feel free to investigate and contribute :)

If you want to contribute with the doc I think the place is https://www.drupal.org/documentation/modules/rest

Many thanks for contributing!!!!

clemens.tolboom’s picture

Documentation page is here

klausi’s picture

Category: Bug report » Support request
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.