08-26-2016 12:13 AM - edited 03-11-2019 12:02 AM
Hi All,
I am new to the Cisco ISE 2.1 and trying to build an ASP.NET MVC 5 application that will create Guest Users using the Guest REST API.
While I am trying to get user details (created using sponsor portal by sponsor user "vspl"), I am able to get the information.
As I am trying to create a guest user account using the Guest REST API from my application and trying get response (HttpWebRequest.GetResponse()), an error "The remote server returned an error: (400) Bad Request." is raising. below is my code:
==============================================================================================
public string postXMLData()
{
destinationUrl = @"https://ise.demo.com:9060/ers/config/guestuser/";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(destinationUrl);
request.Method = "POST"; // to create a new guest user account
request.ContentType = "application/vnd.com.cisco.ise.identity.guestuser.2.0+xml";
request.Accept = "application/vnd.com.cisco.ise.identity.guestuser.2.0+xml";
request.AutomaticDecompression = DecompressionMethods.GZip;
string credidentials = "vspl:Password"; //// "vspl is the Sponsor user"
string authCode = Convert.ToBase64String(Encoding.Default.GetBytes(credidentials)); //to convert user id and password as per RFC 2617
request.Headers.Add("Authorization", "Basic " + authCode);
//// XML data to post to the REST API's POST method
requestXml = @"<?xml version=""1.0"" encoding= ""utf-8"" standalone= ""yes""?><ns2:guestuser xmlns:ns2=""identity.ers.ise.cisco.com""><guestAccessInfo><fromDate>08/17/2016 19:01</fromDate><location>San Jose</location><toDate>11/14/2016 19:01</toDate><validDays>90</validDays></guestAccessInfo><guestInfo><company>VSPL</company><emailAddress>nitin.gupta1@velocis.co.in</emailAddress><enabled>false</enabled><firstName>Nitin</firstName><lastName>Gupta</lastName><notificationLanguage>English</notificationLanguage><phoneNumber>9988880000</phoneNumber><smsServiceProvider>Global Default</smsServiceProvider></guestInfo><guestType>Contractor (default)</guestType><personBeingVisited>deepesh.rastogi@gmail.com</personBeingVisited><reasonForVisit>Meeting</reasonForVisit></ns2:guestuser>";
byte[] bytes;
bytes = System.Text.Encoding.UTF8.GetBytes(requestXml);
request.ContentLength = bytes.Length;
try
{
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
//// Below line is throwing "The remote server returned an error: (400) Bad Request." error
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
if (response.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = response.GetResponseStream();
string responseStr = new StreamReader(responseStream).ReadToEnd();
return responseStr;
}
}
}
catch (Exception ex)
{
throw ex;
}
return null;
}
===========================================================================
Can somebody help me on this.
Thanks in advance.
Nitin Gupta
08-26-2016 03:29 AM
Just quickly looking over your request, you are missing the portalid definition in your xml. Also i believe that the customFields difinition is now mandatory in ISE 2.1. ns:2 should according to the ISE documentation be ns:3.
Example from docu :
08-26-2016 05:04 AM
Hi nielsen,
Thanks for the reply but as per page no. 142 in api ref documentation above Table No. 7-33, only guestType is required field.
I have also tried to add Portal Id, but issue still remains.
Thanks
08-26-2016 05:30 AM
That section does not indicate that guestType is the only required field, it just states that there has to be a guestType in the request.
Did you put an actual portalid number in the request from your ise configuration?
What did you put in the customfields section? If you don't have anything to put there, you can just use
<customFields></customFields>
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