03-28-2016 01:02 PM - edited 02-21-2020 10:30 AM
I have been trying to get the Rest API to work with the ACS server and am struggling with the POST commands. I am using C# but to simplify things I am testing with the Rest Client plugin for Firefox. My URL is:
https://ACSServer01/Rest/Identity/User
And my body is as follows:
<ns2:user>
<description>xxx</description>
<identityGroupName>All Groups:Network Administrator</identityGroupName>
<name>testfred</name>
<changePassword>false</changePassword>
<dateExceedsEnabled>false</dateExceedsEnabled>
<enablePassword>thisisalso!apass</enablePassword>
<enabled>true</enabled>
<password>thisisa!pass</password>
<passwordNeverExpires>false</passwordNeverExpires>
<passwordType>LDAP EMEA</passwordType>
</ns2:user>
But I get a parsing error when I execute it. Can someone tell me what I am missing?
03-29-2016 11:22 AM
I solved the REST client issue by adding a content-type=application/xml in the header and the following line at the top of the body.
<ns2:device xmlns:ns2="networkdevice.rest.mgmt.acs.nm.cisco.com">
So now I am back to the C#. I get an error 400 code when running the following. I can do a GET without an error but it doesn't like my POST. Anyone with experience with this?
Uri address = new Uri("https://" + server + "/Rest/Identity/User");
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
request.PreAuthenticate = true;
request.Credentials = new NetworkCredential(_username, _password);
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
request.Method = "POST";
request.MediaType = "xml";
request.ContentType = "application/xml";
request.Accept = "application/xml";
StringBuilder data = new StringBuilder();
data.Append("<ns2:user ");
data.Append("name='" + "testUser" + "' ");
data.Append("description='" + "test desc" + "' ");
data.Append("identityGroupName='" + "All Groups:Network Administrator" + "' ");
data.Append("changePassword='" + "false" + "' ");
data.Append("enablePassword='" + "thisisalso!apass" + "' ");
data.Append("password='" + "thisisa!pass" + "' ");
data.Append("passwordNeverExpires='" + "false" + "' ");
data.Append("passwordType='" + "Internal Users" + "' ");
data.Append("enabled='" + "true" + "' ");
data.Append("/ns2:user>");
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
request.ContentLength = byteData.Length;
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
response = request.GetResponse() as HttpWebResponse;
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide