AnsweredAssumed Answered

How to update user profile from Wordpress to Apigee?

Question asked by Adriana Jaxon on Feb 10, 2018

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='https://api.enterprise.apigee.com/v1/ 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']  );

Outcomes