Error in  Adding a new user

Version 1
    This document was generated from CDN thread

    Created by: Manas Varma on 23-03-2011 10:18:07 AM
    Hi All,
     
      I am getting an error Bad Request when i Try adding a new user. Can you please look , if there is something wrong that I am doing. Is it the right query for adding a new user.
     
     string ExtQuery = "";
            ExtQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
            ExtQuery += "<User>";
            ExtQuery += "<Alias>varmam</Alias>";
            ExtQuery += "<DtmfAccessId>25311</DtmfAccessId>";
            ExtQuery += "<FirstName>Manas</FirstName>";
            ExtQuery += "<LastName>Varma</LastName>";
            ExtQuery += "<DisplayName>Manas Varma</DisplayName>";
            //ExtQuery += "<PhoneSystemURI>/vmrest/phonesystems/3486d6b3-1b98-4538-98a7-ea89a4758d74</PhoneSystemURI> ";
            ExtQuery += "<CosObjectId>7d241b5a-a278-4df1-b081-475fafc07eee</CosObjectId>";
            ExtQuery += "<SkipPasswordForKnownDevice>true</SkipPasswordForKnownDevice>";
            ExtQuery += "<IsSetForVmEnrollment>false</IsSetForVmEnrollment>";
            ExtQuery += "<IsVmEnrolled>false</IsVmEnrolled>";
            ExtQuery += "<RouteNDRToSender>false</RouteNDRToSender>";
            ExtQuery += "</User>";
          // Response.Write(ExtQuery);
           HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://10.197.210.15/vmrest/users");
           req.Accept = "application/xml";
           req.ContentType = "application/xml";
           req.Method = "POST";
           req.KeepAlive = true;
           byte[] authorizationHeaderBytes = System.Text.Encoding.UTF8.GetBytes("admin" + ":" + "cisco@123");
           string authHeader = "Basic " + Convert.ToBase64String(authorizationHeaderBytes);
           req.Headers.Add("Authorization", authHeader);
           req.Credentials = new System.Net.NetworkCredential("admin", "cisco@123");
           System.Net.ServicePointManager.CertificatePolicy = new Class2.TrustAllCertificatePolicy();
           Stream s = req.GetRequestStream();
           s.Write(System.Text.Encoding.ASCII.GetBytes(ExtQuery), 0, ExtQuery.Length);
           s.Close();
           WebResponse resp = req.GetResponse();
           StreamReader sr = new StreamReader(resp.GetResponseStream());
           string XMLResult = sr.ReadToEnd();
           Response.Write(XMLResult);

    Subject: RE: New Message from Manas Varma in Cisco Unity Connection Provisioning Int
    Replied by: Matthew Penning on 24-03-2011 11:36:24 AM
    Hi ¿ the only suspicious thing I see is the first line:



            ExtQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";



    I would try it without that and see how it works.  Also for testing, I use Firefox and an add-on called ¿Poster¿ that makes it really easy to try POST-ing data before actually coding it up. 



    ~ Matt



    From: Cisco Developer Community Forums [mailto:cdicuser@developer.cisco.com]
    Sent: Wednesday, March 23, 2011 7:18 AM
    To: cdicuser@developer.cisco.com
    Subject: New Message from Manas Varma in Cisco Unity Connection Provisioning Interface (CUPI) - CUPI Questions: Error in Adding a new user



    Manas Varma has created a new message in the forum "CUPI Questions":

    --------------------------------------------------------------
    Hi All,

      I am getting an error Bad Request when i Try adding a new user. Can you please look , if there is something wrong that I am doing. Is it the right query for adding a new user.

    string ExtQuery = "";
            ExtQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
            ExtQuery += "<User>";
            ExtQuery += "<Alias>varmam</Alias>";
            ExtQuery += "<DtmfAccessId>25311</DtmfAccessId>";
            ExtQuery += "<FirstName>Manas</FirstName>";
            ExtQuery += "<LastName>Varma</LastName>";
            ExtQuery += "<DisplayName>Manas Varma</DisplayName>";
            //ExtQuery += "<PhoneSystemURI>/vmrest/phonesystems/3486d6b3-1b98-4538-98a7-ea89a4758d74</PhoneSystemURI> ";
            ExtQuery += "<CosObjectId>7d241b5a-a278-4df1-b081-475fafc07eee</CosObjectId>";
            ExtQuery += "<SkipPasswordForKnownDevice>true</SkipPasswordForKnownDevice>";
            ExtQuery += "<IsSetForVmEnrollment>false</IsSetForVmEnrollment>";
            ExtQuery += "<IsVmEnrolled>false</IsVmEnrolled>";
            ExtQuery += "<RouteNDRToSender>false</RouteNDRToSender>";
            ExtQuery += "</User>";
          // Response.Write(ExtQuery);
           HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://10.197.210.15/vmrest/users");
           req.Accept = "application/xml";
           req.ContentType = "application/xml";
           req.Method = "POST";
           req.KeepAlive = true;
           byte[] authorizationHeaderBytes = System.Text.Encoding.UTF8.GetBytes("admin" + ":" + "cisco@123");
           string authHeader = "Basic " + Convert.ToBase64String(authorizationHeaderBytes);
           req.Headers.Add("Authorization", authHeader);
           req.Credentials = new System.Net.NetworkCredential("admin", "cisco@123");
           System.Net.ServicePointManager.CertificatePolicy = new Class2.TrustAllCertificatePolicy();
           Stream s = req.GetRequestStream();
           s.Write(System.Text.Encoding.ASCII.GetBytes(ExtQuery), 0, ExtQuery.Length);
           s.Close();
           WebResponse resp = req.GetResponse();
           StreamReader sr = new StreamReader(resp.GetResponseStream());
           string XMLResult = sr.ReadToEnd();
           Response.Write(XMLResult);
    --
    To respond to this post, please click the following link:

    <http://developer.cisco.com/web/cupi/forums/-/message_boards/view_message/3240776>

    or simply reply to this email.

    Subject: RE: Error in  Adding a new user
    Replied by: David Wanagel on 25-03-2011 08:47:33 AM
    When errors are returned from the API, it includes a payload with information about what the error is.  Please post the ErrorDetails that were returned with the 400 response.  That will indicate the specific problem the server is having processing your request.
     
    -Dave

    Subject: RE: New Message from Manas Varma in Cisco Unity Connection Provisioning Int
    Replied by: Manas Varma on 25-03-2011 08:27:20 AM
    Hi Matt,

      I tried after removing the XML information that you mentioned , but  still getting the same error. Can you please help me with how this thing willl be acheived, if you have snippets?

    Thanks

    Subject: Re: New Message from Manas Varma in Cisco Unity Connection Provisioning Int
    Replied by: Sascha Monteiro on 25-03-2011 06:46:24 PM
    I am not 100% sure, but shouldn't you provide a templatealias when creating the user?
    your url should look like this then;
    https://10.197.210.15/vmrest/users?templateAlias=voicemailusertemplate

    Subject: RE: Re: New Message from Manas Varma in Cisco Unity Connection Provisioning
    Replied by: Manas Varma on 28-03-2011 05:02:59 AM
    Thanks Sascha.. It worked for me