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.
LVL 1
maaknplanSenior DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
i usually do some debugging using Web Request Tool such as Postman first to determine what parameters to be set before I really go in for the coding part.

you can download Postman and do the testing with URL = destinationUrl

Postman
https://www.getpostman.com/

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maaknplanSenior DeveloperAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.