October 22, 2024
Chicago 12, Melborne City, USA
PHP

Why is SimplyBook API addClient function not working? Error log showing “Client name value is wrong”


I am trying to add a client to the SimplyBook system using JSONRCP. This is called when a new user is added to WordPress as a subscriber using registration form built with the UserRegistration plugin.

When a user tries to register it hangs and then throws an error saying "Client name is wrong". I have tried hard coding some dummy data in and this does work. So it seems that there is an issue with getting the data from the database using the function "$first_name = get_user_meta($user_id, 'first_name', true);"

Any suggestion on what I may be doing wrong would be very much appreciated!

/* Function to run when a new user is created */
function sync_user_created($user_id) {

    $user_id = reset($user)->ID;

    // Get user data
    $user_info = get_userdata($user_id);

    // Check if the user has the role of 'subscriber'
    if (in_array('subscriber', $user_info->roles)) {

        $first_name = get_user_meta($user_id, 'first_name', true);
        $user_email = get_userdata($user_id, 'user_email');
        $user_phone = get_user_meta($user_id, 'phone', true);

        // authenticate connection - this function works
        $JsonRcpClient = SimplyBookAdminAuth();
    
        $clientData = array(
            'name' => $first_name,
            'email' => $user_email,
            'phone' => $user_p  hone
        );

        // add the new client to SimplyBook database - don't send an email
        $JsonRcpClient->addClient($clientData, false);
    
    }

}
// hook into new user registration
add_action('user_register', 'sync_user_created');

The error I am getting from the UserRegistration log is:

2024-10-18T13:05:18+01:00 CRITICAL Uncaught Exception: Request error: Client name value is wrong in C:\wamp64\www\Gruffs\wp-content\themes\understrap-child\includes\JsonRpcClient.php:57Stack trace:#0 C:\wamp64\www\Gruffs\wp-content\themes\understrap-child\includes\sb_client_sync.php(35): JsonRpcClient->_call('addClient', Array)#1 C:\wamp64\www\Gruffs\wp-includes\class-wp-hook.php(326): sync_user_created('861')#2 C:\wamp64\www\Gruffs\wp-includes\class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)#3 C:\wamp64\www\Gruffs\wp-includes\plugin.php(517): WP_Hook->do_action(Array)#4 C:\wamp64\www\Gruffs\wp-includes\meta.php(336): do_action('updated_user_me...', '861', 50, 'first_name', 'Adam')#5 C:\wamp64\www\Gruffs\wp-includes\user.php(1217): update_metadata('user', 50, 'first_name', 'Adam', '')#6 C:\wamp64\www\Gruffs\wp-content\plugins\user-registration\includes\frontend\class-ur-frontend-form-handler.php(253): update_user_meta(50, 'first_name', 'Adam')#7 C:\wamp64\www\Gruffs\wp-content\plugins\user-registration\includes\frontend\class-ur-frontend-form-handler.php(123): UR_Frontend_Form_Handler::ur_update_user_meta(50, Array, 167)#8 C:\wamp64\www\Gruffs\wp-content\plugins\user-registration\includes\class-ur-ajax.php(296): UR_Frontend_Form_Handler::handle_form(Array, 167)#9 C:\wamp64\www\Gruffs\wp-includes\class-wp-hook.php(324): UR_AJAX::user_form_submit('')#10 C:\wamp64\www\Gruffs\wp-includes\class-wp-hook.php(348): WP_Hook->apply_filters('', Array)#11 C:\wamp64\www\Gruffs\wp-includes\plugin.php(517): WP_Hook->do_action(Array)#12 C:\wamp64\www\Gruffs\wp-admin\admin-ajax.php(207): do_action('wp_ajax_nopriv...')#13 {main}thrown in C:\wamp64\www\Gruffs\wp-content\themes\understrap-child\includes\JsonRpcClient.php on line 57



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video