Created
May 31, 2019 21:22
-
-
Save heathdutton/a5f29d53b3303e40edf1690cf42bdd0d to your computer and use it in GitHub Desktop.
Create agents in five9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Example usage: | |
* php five9adduser.php <admin username> <admin password> <agent email> <agent firstname> <agent lastname> <agent password> | |
*/ | |
error_reporting(E_ALL); | |
$user = $argv[1]; | |
$pass = $argv[2]; | |
$email = $argv[3]; | |
$firstName = $argv[4]; | |
$lastName = $argv[5]; | |
$agentPass = $argv[6]; | |
echo 'Logging in as '.$user. PHP_EOL; | |
echo 'Creating user '.$email. PHP_EOL; | |
$wsdl_five9 = "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl&user=$user"; | |
try { | |
$client_five9 = new SoapClient( | |
$wsdl_five9, [ | |
'login' => $user, | |
'password' => $pass, | |
'trace' => true, | |
] | |
); | |
$result = $client_five9->createUser( | |
[ | |
'userInfo' => [ | |
'agentGroups' => 'Team-Lorie Arango', | |
'generalInfo' => [ | |
'active' => true, | |
'canChangePassword' => true, | |
'EMail' => $email, | |
'firstName' => $firstName, | |
'lastName' => $lastName, | |
'mustChangePassword' => false, | |
'password' => $agentPass, | |
'userName' => $email, | |
], | |
'roles' => [ | |
'agent' => true, | |
], | |
], | |
] | |
); | |
$variables = get_object_vars($result); | |
$resp = get_object_vars($variables['return']); | |
if (isset($resp['generalInfo']->userName)) { | |
echo "User created: ".$resp['generalInfo']->userName; | |
} else { | |
Throw new \Exception('Unexpected result from five9 '.var_dump($resp, true)); | |
} | |
} catch (Exception $e) { | |
echo 'ERROR: '.$e->getMessage(); | |
exit(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment