Wouldn’t it be great if new WordPress user registrations automatically became leads in SuiteCRM? In this tutorial, we’ll show you how to achieve this using SuiteCRM V8 API and WordPress action hooks.
By the end of this guide, you’ll be able to:
✅ Capture new WordPress users and push them to SuiteCRM as Leads
✅ Assign Lead Source = Web Site for tracking purposes
✅ Automate the process so every new user is seamlessly added to SuiteCRM
✅ Use SuiteCRM workflows to automatically add new leads to your newsletter list
How are the Leads Sent? (Updated 2-Step Process)
Since some WordPress user metadata isn’t immediately available at the time of registration, we’ve split the process into two steps to ensure all data is captured before pushing to SuiteCRM.
Step 1: Capture User Registration & Check Allowed Roles
- When a new user registers, the function is triggered by
add_action('user_register', ...)
- It retrieves the user’s ID and their role(s).
- If the user’s role matches the allowed list, the sync process proceeds. Otherwise, it’s skipped.
- The function waits for WordPress to fully store the user metadata before making the API request.
Step 2: Retrieve User Data & Push to SuiteCRM
- It fetches the full user profile, including first name, last name, company, and phone number.
- Calls
suitecrm_get_access_token()
to authenticate. (Fails if no valid token) - Prepares the API request (
$lead_data
) with:- First Name & Last Name
- Phone
- Company (billing_company)
- Lead Source = Web Site
- Status = New
- Assigned User = pablostevens (User ID: 5)
- Sends the lead data to SuiteCRM’s V8 API via
wp_remote_post()
. - Logs errors if the request fails or logs the response if successful.
Enable & Configure SuiteCRM V8 API
efore integrating with WordPress, ensure the V8 API is enabled in SuiteCRM.
- Generate API Client Credentials in SuiteCRM:
- Navigate to Admin > OAuth2 Clients & Tokens
- Click Create OAuth2 Client
- Enter a name (e.g.,
WordPress API
) - Set Client Secret and Client ID
- Click Save
- Copy the Client ID and Client Secret for use in WordPress
- Verify API Access:
- Test the API with Postman to ensure authentication is working
- Use the
/Api/access_token
endpoint to obtain an access token
See my previous tutorial for setting up the OAuth2 Clients and Tokens
Note: For SuiteCRM 8, the URL is /legacy/Api/access_token
Set Up WordPress Hook for User Registration
WordPress provides the user_register
hook, which allows us to trigger an action when a new user registers.
Add the following code to your WordPress theme’s functions.php
file or a custom plugin:
// Step 1: Store user ID after registration
add_action('user_register', 'suitecrm_store_user_id_after_registration', 10, 1);
function suitecrm_store_user_id_after_registration($user_id) {
set_transient("suitecrm_user_$user_id", $user_id, 60); // Store user ID for 60 seconds
}
// Step 2: Wait for meta to be updated before pushing to SuiteCRM
add_action('profile_update', 'sync_new_user_to_suitecrm', 10, 2);
Authenticate with SuiteCRM V8 API
To interact with SuiteCRM, we must first obtain an access token.
function get_suitecrm_access_token() {
$client_id = 'your-client-id';
$client_secret = 'your-client-secret';
$api_url = 'https://your-suitecrm-instance/Api/access_token';
$response = wp_remote_post($api_url, [
'body' => [
'grant_type' => 'client_credentials',
'client_id' => $client_id,
'client_secret' => $client_secret
],
'timeout' => 15,
'sslverify' => false
]);
if (is_wp_error($response)) {
error_log('SuiteCRM API Auth Error: ' . $response->get_error_message());
return null;
}
$body = json_decode(wp_remote_retrieve_body($response), true);
return $body['access_token'] ?? null;
}
Push New User Data to SuiteCRM
Now that we have authentication, we can send new leads to SuiteCRM.
function sync_new_user_to_suitecrm($user_id, $old_user_data) {
// Check if this is a newly registered user by looking up the transient
if (!get_transient("suitecrm_user_$user_id")) {
return; // Exit if this is not a new user
}
delete_transient("suitecrm_user_$user_id"); // Remove transient after use
$user_info = get_userdata($user_id);
$user_roles = (array) $user_info->roles; // Get user's roles
// Allowed roles for SuiteCRM sync
$allowed_roles = suitecrm_get_allowed_roles(); // Function to return allowed roles
$should_sync = array_intersect($user_roles, $allowed_roles);
// Log user details for debugging
//error_log('User Info Retrieved: ' . print_r($user_info, true));
//error_log('First Name: ' . get_user_meta($user_id, 'first_name', true));
//error_log('Last Name: ' . get_user_meta($user_id, 'last_name', true));
//error_log('User Roles: ' . print_r($user_roles, true));
// Skip if user role is not allowed
if (empty($should_sync)) {
error_log('SuiteCRM Sync Skipped: User role not in allowed list.');
return;
}
// error_log('SuiteCRM Sync Function Triggered for User ID: ' . $user_id);
// Get API token
$token = suitecrm_get_access_token();
if (!$token) {
error_log('SuiteCRM API Authentication Failed - Could not push lead.');
return;
}
// Prepare Lead Data
$post_url = trailingslashit(get_option('suitecrm_url')) . 'legacy/Api/V8/module';
$lead_data = [
'data' => [
'type' => 'Leads',
'attributes' => [
'first_name' => get_user_meta($user_id, 'first_name', true) ?: 'Unknown',
'last_name' => get_user_meta($user_id, 'last_name', true) ?: $user_info->user_login,
'email1' => $user_info->user_email,
'phone_work' => get_user_meta($user_id, 'billing_phone', true) ?: '',
'account_name'=> get_user_meta($user_id, 'billing_company', true) ?: '',
'lead_source' => 'Web Site', //Assign lead source
'status' => 'New', // Assign lead status
'assigned_user_id' => '1' // Assign to user ID 1 (pablostevens)
]
]
];
// Send API Request
$response = wp_remote_post($post_url, [
'headers' => [
'Content-Type' => 'application/vnd.api+json',
'Authorization' => 'Bearer ' . $token
],
'body' => json_encode($lead_data),
'timeout' => 15
]);
// Log for debugging
if (is_wp_error($response)) {
error_log('SuiteCRM Lead Creation Failed: ' . $response->get_error_message());
} else {
$response_body = wp_remote_retrieve_body($response);
// error_log('SuiteCRM Lead Creation Response: ' . $response_body);
}
}
The wp_remote_post()
function in WordPress is responsible for making an HTTP POST
request. In this case, it’s used to send the lead data to SuiteCRM’s V8 API.
Automate Lead Segmentation Using SuiteCRM Workflows
Now that WordPress subscribers are added as leads, we can use SuiteCRM Workflows to segment them.
- Navigate to Admin > Workflow
- Create New Workflow:
- Module: Leads
- Run On: New Records
- Define Conditions:
- If Lead Source = Web Site
- Then Action: Add to Newsletter Target List
This ensures that every WordPress subscriber is automatically added to your email marketing campaign.

Testing & Debugging
- Register a test user in WordPress
- Check SuiteCRM Leads Module for the new entry
💡 Need help with SuiteCRM or API development? I specialize in SuiteCRM consulting, development, and integration services. Reach out for assistance! 🚀
You can download my plugin code here and modify as you like: