Skip to main content

To PATCH a user is to update an existing user... actually the current user logged in.

An introduction to PATCH command can be viewed on the Node PATCH command screen.  Secondly, review the user API, as it outlines the structure for each of the fields that can be included.  Finally, if you haven't already reviewed the introduction into setting up RESTful hal+json refer to the set-up documentation.  Also see the Query - user screen.  To be able to get, patch or patch you need to log in the member so you can retrieve their user id (uid).

Example of a PATCH

Using the structure outline in PATCH command screen and fields defined in the user API screen, following is an example that bridges these two together:

Request: {domain}/user/{uid}?_format=hal_json

Content-Type: application/hal+json

X-CSRF-Tokenthis dependant on the login credentials

Accept: application/hal+json

Body:

{"_links":{
"type":{"href":"http://your-site.com/rest/type/user/user"}},
"pass": [
        {"existing":"r#sT", "value": "r#sT"}
    ],
"mail":{
   "value":"updatedtestuser@mailserver.com"
 }
}

 

Other examples of applying a patch

First name:

"field_firstname":{"value":"William"}

Last name:

"field_lastname":{"value":"Redpath"}

Nick name:

"field_nickname":{"value":"Bill"}

Email:

"mail":{"value":"updatedtestuser@your-site.com"}

Gender:

"field_gender":{"value":"male"}
accepted values: male, female

Mobile:

"field_mobile":{"value":"0412436"}

accepted values: integer

DoB:

"field_dob":{"value":"1989-08-07"}

accepted values: integer in date format yyyy-mm-dd

User image:

"_embedded":
    { 
        "https://your-site.com/rest/relation/user/user/user_picture": [
        {   
            "uuid": [
            {
                "value": "ea63b5e8-3f47-4320-aad9-bfe835d4f8ab"
            }] 
        }] 
    }

The user's image is added using _embedded array.  For more details in relation to adding or updating a user's image see the example outlined on adding an user's image.

Related articles

Andrew Fletcher04 Apr 2025
Managing .gitignore changes
When working with Git, the .gitignore file plays a critical role in controlling which files and folders are tracked by version control. Yet, many developers are unsure when changes to .gitignore take effect and how to manage files that are already being tracked. This uncertainty can lead to...
Andrew Fletcher26 Mar 2025
How to fix the ‘Undefined function t’ error in Drupal 10 or 11 code
Upgrading to Drupal 10.4+ you might have noticed a warning in their code editor stating “Undefined function ‘t’”. While Drupal’s `t()` function remains valid in procedural code, some language analysis tools — such as Intelephense — do not automatically recognise Drupal’s global functions. This...
Andrew Fletcher17 Mar 2025
Upgrading to PHP 8.4 challenges with Drupal contrib modules
The upgrade from PHP 8.3.14 to PHP 8.4.4 presents challenges for Drupal 10.4 websites, particularly when dealing with contributed modules. While Drupal core operates seamlessly, various contrib modules have not yet been updated to accommodate changes introduced in PHP 8.4.x. This has resulted in...