Modifing users

Version 1
    This document was generated from CDN thread

    Created by: Chris Bomba on 01-02-2010 05:50:11 PM
    I have 500 mailboxes that need the Alias updated.  I am going to use a file that I will open up and go through it and match the Alias column, do a search to return the ObjectID then do a post to modify that field.  When I try to post a change I get the following error:
     
     
     
    An Error Occurred
    302 Moved Temporarily

    HTTP/1.1 302 Moved Temporarily
    Connection: close
    Date: Mon, 01 Feb 2010 17:48:31 GMT
    Location: https://X.X.X.X:8443/vmrest/users/18b450ab-4be0-42d2-9189-78b695f52fdf
    Server:
    Content-Length: 0
    Client-Date: Mon, 01 Feb 2010 17:48:32 GMT
    Client-Peer: X.X.X.X:80
    Client-Response-Num: 1
     
     

    Subject: RE: Modifing users
    Replied by: Matthew Penning on 11-02-2010 12:35:58 AM
    Hi Chris - were ever able to figure out what was happening here?  From what you describe it sounds like it should work.
     
    I have 500 mailboxes that need the Alias updated.  I am going to use a file that I will open up and go through it and match the Alias column, do a search to return the ObjectID then do a post to modify that field.  When I try to post a change I get the following error:
     
     
     
    An Error Occurred
    302 Moved Temporarily

    HTTP/1.1 302 Moved Temporarily
    Connection: close
    Date: Mon, 01 Feb 2010 17:48:31 GMT
    Location: https://X.X.X.X:8443/vmrest/users/18b450ab-4be0-42d2-9189-78b695f52fdf
    Server:
    Content-Length: 0
    Client-Date: Mon, 01 Feb 2010 17:48:32 GMT
    Client-Peer: X.X.X.X:80
    Client-Response-Num: 1
     
     


    Subject: RE: Modifing users
    Replied by: David Wanagel on 11-02-2010 12:16:34 PM
    Somehow I missed this question, a 302 is generally the result of trying to access the API using HTTP instead of HTTPS.  The web application that hosts the API requires a secure transport, so it will redirect HTTP requests to the HTTPS port.
     
    -Dave

    Subject: RE: Modifing users
    Replied by: Chris Bomba on 23-02-2010 06:15:54 PM
    I made the change to https and now I get a 401 error.  I am not Perl guru and so I am posting my code. 
     
     1#!/usr/bin/perl -w
     2
     3use strict;
     4
     5use LWP::UserAgent;
     6use HTTP::Request::Common;
     7
     8
     9my $userAgent = LWP::UserAgent->new(agent => 'perl put');
    10
    11$userAgent->credentials(
    12    '10.1.1.1:443',
    13    'Cisco VTG Realm',
    14    'api' => 'l3tm3!n'
    15);
    16
    17
    18my $message = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
    19    <User>
    20    <Alias>abcde\@domain.com</Alias>
    21    </User>";
    22
    23my $response = $userAgent->request(POST 'https://10.1.1.1/vmrest/users/18b450ab-4be0-42d2-9189-78b695f52fdf',
    24    [Content_Type => 'text/xml',
    25    Content => $message
    26    ]
    27);
    28
    29print $response->error_as_HTML unless $response->is_success;
    30
    31print $response->as_string;
    32
    33exit;

     
     
    The user I want to change has an alias of 'abcde' and I want to update that alias to 'abcde@domain.com'.  I can then go back through and run an LDAP sync.

    Subject: RE: Modifing users
    Replied by: Chris Bomba on 23-02-2010 06:26:27 PM
    More on the error I get:
     
    An Error Occurred
    401 Unauthorized

    HTTP/1.1 401 Unauthorized Connection: close
    Date: Tue, 23
    Feb 2010 18:09:14 GMT
    Server: WWW-Authenticate:
    Basic realm="Cisco VTG Realm"

    Content-Length: 2113
    Content-Type: text/html;charset=utf-8
    Client-Date: Tue, 23
    Feb 2010 18:09:15 GMT
    Client-Peer: 10.1.1.1:443
    Client-Response-Num: 1

    Client-SSL-Cert-Issuer: /CN=****/OU=****/O=****/L=****
    Client-SSL-Cert-Subject:
    /CN=****/OU=****/O=****/L=****
    Client-SSL-Cipher: AES256-SHA

    Client-SSL-Warning: Peer certificate not verified Title:
    Cisco System - Error
    report

    Subject: RE: Modifing users
    Replied by: Matthew Penning on 23-02-2010 07:05:19 PM
    Hi Chris - I'm not a Perl expert either, but I did put together a small Perl sample that handles authentication. Look in "Recent Downloads" for   <a>cupi-setpw-example.pl</a> or try clicking that link.

    ~ Matt
     

    Subject: RE: Modifing users
    Replied by: Chris Bomba on 23-02-2010 07:11:23 PM
    I was just coming back on here to tell everyone that I used that one and change the password section to update the Alias.  Thank you very much for your work.  I just need to figure out how to make that script open a file, go through each line and pull the alias out of that file, put that alias in the script, change that alias, then move on to the next line.
     
    Here is what I changed.
     
     1sub setalias {
     2    my $userURI=shift(@_);
     3    my $newalias=shift(@_);
     4   
     5    my $credentials="<User><Alias>$newalias</Alias></User>";
     6    my $url="https://$SERVER$userURI";
     7    my $ua = LWP::UserAgent->new;
     8    my $header = HTTP::Headers->new;
     9    $header->header("Content-Type","application/xml");
    10    my $req = HTTP::Request->new(PUT => $url, $header, $credentials);
    11    $req->authorization_basic($USER,$PASSWORD);
    12    my $response = $ua->request($req);
    13   
    14    &checkerror($response);
    15}
    16
    17# Lookup user by alias
    18my $URI=&userlookup('OriginalAlias');
    19print "Found user: ", $URI, "\n";
    20
    21# Set password
    22&setalias($URI,"NewAlias");
    23print "Alias successfuly set!", "\n";