Add user with PERL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2015 05:49 AM
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
- Labels:
-
Voicemail (Unity Connection)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2015 05:57 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2015 08:35 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2015 03:23 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2015 02:49 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2015 03:24 AM
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>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2015 04:27 AM
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.
