My Collab Lab

mycollablab.org

User Input Update

September 15, 2017 PHP Voicemail

I was working with a customer recently that required a zero out option for all users in VM. This is a bit of a task since you cannot adjust via the normal import/export process, but you can “bulk edit by csv” in order to change multiple users at one. This is still a bit of a task since each user import we do have 5-10 different groups with the same zero option, but still doable. The tough question came when they requested a report of wha user zero outs to what extension so they could check a bunch of users they added were in correct. Because you can’t see these options in export your left searching on ciscounitytools.com for a solution, or use the API.

Here are 2 scripts I used to first pull each user with zero options and some other info so that the customer could update a csv file. The second script takes that csv file and updates users accordingly.

Note that this is a sub 1k user setup. The first script pulls all users at once. In a large enviroment this would need to be looped through 1k at a time until complete. Also the update file doesn’t check for fields that don’t exist. So if you tell it to update to nothing, it will. Make sure all “new options” are filled out in the csv or better, delete lines that dont need updated.

Get User Options:


#!/usr/bin/php -q
<?php

function send_cupi($method,$uri,$data) {

  $api['url']           = "https://10.10.10.10";
  $api['auth_token']  = base64_encode('ucadmin:StuffHere');

    $uri .= $data;
    $options = array(
            'http' => array(
                'header'  => "Authorization: Basic ".$api['auth_token'].
                     " \r\nAccept: application/json \r\nContent-type: application/json\r\n",
                'method'  => 'GET',
            ),
        "ssl"=>array(
            "verify_peer"=>false,
            "verify_peer_name"=>false,
            )
        );

    $context  = stream_context_create($options);
    $result = json_decode(file_get_contents($api['url'].$uri, false, $context));

    return $result;
}

$cupiResponse = send_cupi("get","/vmrest/users","");
$count = 0;
foreach ( $cupiResponse->User as $vmUser ) {

    $menuResponse = send_cupi("get","/vmrest/handlers/callhandlers/".$vmUser->CallHandlerObjectId."/menuentries/0","");

    if ( $menuResponse->Action = '7' ){
        $TransferNumber = $menuResponse->TransferNumber;
    } else {
        $TransferNumber = "Not Configured";
    }

    $vmUserList[$count] = array( "Alias"=>$vmUser->Alias
                ,"FirstName"=>@$vmUser->FirstName
                ,"LastName"=>@$vmUser->LastName
                ,"Department"=>@$vmUser->Department
                ,"DtmfAccessId"=>@$vmUser->DtmfAccessId
                ,"ZeroOption"=>@$TransferNumber
                ,"CallHandlerObjectId"=>@$vmUser->CallHandlerObjectId
        );

    foreach ($vmUserList[$count] as $csv) {
        echo $csv.",";
    }
    echo "\n";
    $count++;
}

?>

Update User Options:


#!/usr/bin/php -q
<?php

function send_cupi($method,$uri,$data) {

  $api['url']           = "https://10.10.10.10";
  $api['auth_token']  = base64_encode('ucadmin:password');

    switch ($method) {
        case "get":
            $uri .= $data;
            $options = array(
                'http' => array(
                    'header'  => "Authorization: Basic ".$api['auth_token'].
                         " \r\nAccept: application/json \r\nContent-type: application/json\r\n",
                    'method'  => 'GET',
                ),
                "ssl"=>array(
                    "verify_peer"=>false,
                    "verify_peer_name"=>false,
                    )
                );
        break;
        case "put":
            $options = array(
                'http' => array(
                    'header'  => "Authorization: Basic ".$api['auth_token']." \r\nContent-type: application/json\r\n",
                    'method'  => 'PUT',
                    'content' => json_encode($data),
                ),
            "ssl"=>array(
                "verify_peer"=>false,
                "verify_peer_name"=>false,
                )
            );
        break;
    }
    $context  = stream_context_create($options);
    $result = json_decode(file_get_contents($api['url'].$uri, false, $context));

    return $result;
}

if (($handle = fopen('./update.csv', "r")) !== FALSE) {
    while ( ($data = fgetcsv($handle, 1000, ",")) !== FALSE ) {
        echo $data[6]." - ".$data[7]."\n";

        $updateInfo = array("Action"=>"7","TransferNumber"=>$data[6]);
        $getZeroOut = send_cupi("put","/vmrest/handlers/callhandlers/".$data[7]."/menuentries/0",$updateInfo);

        echo $getZeroOut;

        echo "\n";
    }
    fclose($handle);
}

?>
csvcupidtmfunityuser input

LetsEncrypt an Expressway

Spark Bot Security


Jon Snipes
LinkedIn

My career progressed from head butcher to Collaboration CCIE. There isn’t much technically that carries over between professions, but 8 years of direct customer service experience and squeezing margin out of processes provided a solid base and direction for the rest of my career. My focus today is deep into collaboration messaging, voice and video with the expertise to develop processes and programmatic solutions to complex business problems.

Principal Architect at Cloverhound
CCIE Collaboration 51786
Cisco Webex Expert
2018-2021 Cisco Champion

Categories
  • Cloud (4)
  • Contact Center (1)
  • Development (1)
  • PHP (10)
  • Python (3)
  • Uncategorized (1)
  • Video (2)
  • Voice (12)
  • Voicemail (5)
  • Webex (7)
Recent Posts
  • Azure OAuth2.0 User Authentication December 4, 2021
  • Pass-through Gateway Routing and Dial Peer Groups December 4, 2021
  • Get Started Coding with Python: System Setup and Running Scripts December 4, 2021
  • Exporting CUCM to an Offline Local DB with Python December 4, 2021
  • Connecting to UCCX INFORMIX DB with Python on Linux December 4, 2021
Proudly powered by WordPress | Theme: Doo by ThemeVS.