How to update user profile from WordPress to Apigee?

When a user register on WordPress a developer is created on my Apigee organization. I achived this functionality by creating a plugin which uses wp_remote_post(). I am also able to delete account from both WordPress and Apigee by using wp_remote_request() and specifying method DELETE. Now I want to update the acount of the user. This means that for example if a user change first name,it should be changed in both WordPress and Apigee. From Apigee side I need to use PUT method. According to WordPress Codes you may meet with various degrees of success when using PUT. Bellow is the code of my UPDATE plugin:

<?php  //DELETE ACCOUNT function do_stuff(){$current_user = wp_get_current_user();$current_user = wp_get_current_user();if ( !($current_user instanceof WP_User) )     return; //create a recourse link$urlbegin=' organizations/orgname/developer  s/';$varemail= $current_user->user_email ;$url= $urlbegin.$varemail; $args = array( 'method' => 'PUT','headers'=> array( 'Authorization' => 'Basic  xxxxxxxxxxxxx'));$response = wp_remote_request( esc_url_raw($url), $args );if ( is_wp_error( $response ) ) {$error_message = $response->get_error_message();echo Something went wrong: $error_message; }  else { echo 'Response:<pre>';//print_r( $response );echo '</pre>'; }}add_action('update_profile','do_stuff'); ?>

I used the same structure to delete user account. Is this going to work with put? Where do I need to put the body with the data that I want to update. This is the body:

$arg_data = array('email'=> $_POST['user_email'],  firstName   =>$_POST['first_name'], lastName => $_POST['last_name'] , userName =>    $_POST['user_login']  );

Share This Post

Leave a Reply