Title: Create agent programmatically
Last modified: October 4, 2023

---

# Create agent programmatically

 *  Resolved [gonmial](https://wordpress.org/support/users/gonmial/)
 * (@gonmial)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/craete-agent-programmatically/)
 * Would you be so kind to tell me how I can create new Agent (support staff) programmatically
   from other wordpress module?
    -  This topic was modified 2 years, 6 months ago by [gonmial](https://wordpress.org/support/users/gonmial/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [gonmial](https://wordpress.org/support/users/gonmial/)
 * (@gonmial)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/craete-agent-programmatically/#post-17100375)
 * If someone interested in this, I solve this problem with this code:
 *     ```wp-block-code
       use FluentSupport\App\Modules\PermissionManager;
   
       function CreateNewAgentInFluentSupport($email){
   
       	$data = array();
       	$data['email'] = $email;
       	$user = get_user_by('email', $data['email']);
       	$data['user_id'] = $user->ID;
   
       	if (empty($data['first_name'])) {
       		$data['first_name'] = $user->first_name;
       	}
   
       	if (empty($data['last_name'])) {
       		$data['last_name'] = $user->last_name;
       	}
   
       	$permissions = array('fst_manage_own_tickets');
   
       	try {
   
       		$agentsApi = FluentSupportApi('agents');
       		$newAgent = $agentsApi->createAgentWithOrWithoutWpUser($data);
   
       		if (!$newAgent==false) {
       			PermissionManager::attachPermissions($user, $permissions);
       		}
       		else {
       			return 'User not created';
       		}
   
       	} catch (Throwable $e) {
       		return 'Get error: '.$e->getMessage();
       	}
   
       }
       ```
   
 *  Plugin Support [Ahsan Chowdhury](https://wordpress.org/support/users/ahsannayem/)
 * (@ahsannayem)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/craete-agent-programmatically/#post-17104364)
 * Hello [@gonmial](https://wordpress.org/support/users/gonmial/) ,
 * Thank you for sharing the code and contribution to the community.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Create agent programmatically’ is closed to new replies.

 * ![](https://ps.w.org/fluent-support/assets/icon.svg?rev=2628677)
 * [Fluent Support - Helpdesk & Customer Support Ticket System](https://wordpress.org/plugins/fluent-support/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/fluent-support/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/fluent-support/)
 * [Active Topics](https://wordpress.org/support/plugin/fluent-support/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/fluent-support/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/fluent-support/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Ahsan Chowdhury](https://wordpress.org/support/users/ahsannayem/)
 * Last activity: [2 years, 6 months ago](https://wordpress.org/support/topic/craete-agent-programmatically/#post-17104364)
 * Status: resolved