Is there a way that you can update the user base on the username not with the ID? As I am trying to create a user then will add on another website but the ID created is different with the one on my main website. Now my problem is updating that user base on username. Is it possible?
This is what I've tried in updating and it is already functional but base on ID.
UPDATED CODE with Authentication
function update_user_api( $entry, $form ) {
$firstname = $entry[3];
$lastname = $entry[4];
$email = $entry[5];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://mywebsite/wp-json/wp/v2/users/11?context=edit", //I would like to change this to username if possible
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "first_name=".$firstname."&last_name=".$lastname."",
CURLOPT_HTTPHEADER => array(
"authorization: Basic MDAwOjAwMA==",
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded",
"postman-token: 0a02f782-eab1-e4d7-e866-737c6894fad3"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
}
add_action( 'gform_after_submission_16', 'update_user_api', 10, 2 );
We also enconter this problem, our work around was saving the userID that is created from another website as usermeta of the user on the main website and use that for updating via wp rest api. Hope it helps. Cheers