cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
911
Views
0
Helpful
6
Replies

Add user with PERL

m.batts
Level 4
Level 4

Hi,

I'm trying to add a user using perl and seem to be struggling, I'm quite familiar with PERL with AXL\SOAP but the REST formatting seems to be eluding me

use LWP::UserAgent;
use LWP::Protocol::https;
$LOGFILE="logfile.txt";
$USER = '<removed>';
$PASSWORD = '<removed>';

$starttime=time();
  $xml = " <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<User>
<Alias>jdoe</Alias>
<DtmfAccessId>7890</DtmfAccessId>
</User>";
  $url="https://10.64.144.49/vmrest/users?templateAlias=voicemailusertemplate";
  $ua = LWP::UserAgent->new;
  $header = HTTP::Headers->new;
  $req = HTTP::Request->new(POST => $url,
  [
  Content => $xml
  ],
  );
 
  $req->authorization_basic($USER,$PASSWORD);
  $req->content_type('application/xml');
  print $req->as_string;
  $response = $ua->request($req);
  #print $response->as_string;
 
  $runtime=time()-$starttime;
  print "This script ran for $runtime seconds \n";
exit

I keep getting

HTTP Status 400 - Bad Request

      </div>            <p>                <b>                    type:

      </b> Status report            </p>            <p>                <b>messag

e:               </b> Bad Request            </p>            <p>

<b>description:               </b> The request sent by the client was syntactica

lly incorrect.            </p>        </div>    </body></html>

This script ran for 1 seconds

}        </style>    </head>    <body>        <div id="logo">            <img s
rc="/ciscologo.gif" alt="Cisco Systems, Inc." />        </div>        <div id="c
ontent">            <div id="content-header">HTTP Status 400 - Bad Request
      </div>            <p>                <b>                    type:
      </b> Status report            </p>            <p>                <b>messag
e:               </b> Bad Request            </p>            <p>
<b>description:               </b> The request sent by the client was syntactica
lly incorrect.            </p>        </div>    </body></html>
This script ran for 1 seconds

Can't see where I'm going wrong?

regards

mark

6 Replies 6

lindborg
Cisco Employee
Cisco Employee

I'm on a Perl guy but it might help to see what's actually being sent so you can see what the body format complaint is about.  Can you run Fiddler on your client box and capture the actual header and body details to look at?

npetrele
Cisco Employee
Cisco Employee

Feel free to ignore this because my experience with REST is with other aspects of Cisco operations, not with UC, but in the past, I found I had to do something like this in REST request:


$xml = " xml='<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> ... '"

Seems redundant, I know, but specifying xml= made it work. 

Hi  Nicholas , tried adding

$xml="xml='<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>$xml="xml='<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>

same error I'm afraid

davidn#
Cisco Employee
Cisco Employee

Mark,

Doesn't matter which language you use, if you can capture and provide the actual HTTP request, we can take a look and let you know what's wrong. (Fiddler would be a good tool to use to capture it).

Regards,

David

Here is my post

Sorry for the delayed reply

POST https://10.64.144.49/vmrest/users?templateAlias=voicemailusertemplate
Authorization: Basic bWJhdHRzOkJtdzc0MCEy
User-Agent: libwww-perl/5.834
Content-Type: application/xml

xml='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<User>
<Alias>jdoe</Alias>
<FirstName>Mark</FirstName>
<LastName>Batts</LastName>
<DtmfAccessId>7890</DtmfAccessId>
</User>

Sorted it , just removed the line

xml='<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> ... '"xml='<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> ... '" completely and it worked first time.

thanks for clues on this.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: