I have managed to do this with hooking into rest_insert_user
.
I send an array like this:
var data = {
first_name: user.first_name,
last_name: user.last_name,
name: user.display_name,
email: user.email,
description: user.description,
meta: {
'wpcf-phone': user.phone,
'wpcf-institution': user.institution,
'wpcf-birthday': Math.round(new Date(user.birthday).getTime()/1000)
}
};
And treat only the meta data through the hook as this:
function aa_user_update($user, $request, $create)
{
if ($request['meta']) {
$user_id = $user->ID;
foreach ($request['meta'] as $key => $value) {
update_user_meta( $user_id, $key, $value );
}
}
}
add_action( 'rest_insert_user', 'aa_user_update', 12, 3 );
The ordinary fields of the user are updated normally by the API.