Topics In Demand
Notification
New

No notification found.

Blog
How to update user profile from Wordpress to Apigee?

February 10, 2018

IOT

728

0

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']  );


That the contents of third-party articles/blogs published here on the website, and the interpretation of all information in the article/blogs such as data, maps, numbers, opinions etc. displayed in the article/blogs and views or the opinions expressed within the content are solely of the author's; and do not reflect the opinions and beliefs of NASSCOM or its affiliates in any manner. NASSCOM does not take any liability w.r.t. content in any manner and will not be liable in any manner whatsoever for any kind of liability arising out of any act, error or omission. The contents of third-party article/blogs published, are provided solely as convenience; and the presence of these articles/blogs should not, under any circumstances, be considered as an endorsement of the contents by NASSCOM in any manner; and if you chose to access these articles/blogs , you do so at your own risk.


© Copyright nasscom. All Rights Reserved.