Link to home
Start Free TrialLog in
Avatar of maaknplan
maaknplanFlag for South Africa

asked on

ASP.Net Post Attributes

Hi All

I am clearly missing something here. I am trying to send calls to an API for a product called ServiceDeskPlus.

The operation name "ADD_REQUEST"  should be sent as a "POST attribute" with key "OPERATION_NAME".

The technician key should be sent as a "POST attribute" with key "TECHNICIAN_KEY".

Input is an XML string sent as a "POST attribute" with key "INPUT_DATA".

The full documentation page is found here.

The code I am using to create the Post Attributes is:
public void CreateSupportDeskItem(ref SupportItem supportItem, string clientCode = "")
        {
            string destinationUrl = Properties.Settings.Default.ServiceDeskEndPoint;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(destinationUrl);

            string group = Properties.Settings.Default.ServiceDeskGroup;
            string status = Properties.Settings.Default.ServiceDeskStatus;
            string service = Properties.Settings.Default.ServiceDeskService;
            string technicianKey = Properties.Settings.Default.ServiceDeskAPIKey;

            string requestXml;

            if (string.IsNullOrEmpty(clientCode))
                requestXml = GenerateRequestXml(supportItem,
                                         group, status, service);
            else
                requestXml = GenerateRequestXml(supportItem, group, status, service, clientCode);

            NameValueCollection outgoingQueryString = HttpUtility.ParseQueryString(String.Empty);
            outgoingQueryString.Add("OPERATION_NAME", "ADD_REQUEST");
            outgoingQueryString.Add("TECHNICIAN_KEY", technicianKey);
            outgoingQueryString.Add("INPUT_DATA", requestXml);
            string postData = outgoingQueryString.ToString();

            byte[] bytes;
            bytes = Encoding.ASCII.GetBytes(postData);
            request.ContentType = "application/x-www-form-urlencoded"; 
            request.ContentLength = bytes.Length;
            request.Method = "POST";

            Stream dataStream = request.GetRequestStream();
            dataStream.Write(bytes, 0, bytes.Length);
            dataStream.Close();

            HttpWebResponse response;
            response = (HttpWebResponse)request.GetResponse();
            if (response.StatusCode == HttpStatusCode.OK)
            {
                Stream responseStream = response.GetResponseStream();
                string responseStr = new StreamReader(responseStream).ReadToEnd();
                Console.WriteLine(responseStr);
                int ticketId = ParseSupportDeskID(responseStr);

                supportItem.RequestID = ticketId;
            }
            else
            {
                throw new NotImplementedException("The Http Web Response failed!");
            }

        }

Open in new window


However when I make the call, the response I get is "No operation name specified in request". So clearly I have not correctly set the "Post Attribute".

Please can someone advise.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maaknplan

ASKER

Thanks for this. It turns out the Post attributes were being correctly set, but the XML going into "INPUT_DATA" was missing the details node. Once I used PostMan I picked up the error immediately. I recommend PostMan for anyone working with any kind of a service.