Retrieve info from QuickFile on C#

Hi,

Been trying to get a simple app to communicate with QuickFile API but I am always getting an error on the XML.

I’ve used part of the code example as a base to start but still not working.

Can someone please give me some help.

My code:

                var request = (HttpWebRequest)WebRequest.Create(new Uri("https://quickfile.co.uk/WebServices/API/invoices.ashx"));
                request.Method = "POST";
                request.ContentType = "application/xml;charset=UTF-8";
                request.KeepAlive = false;
                request.Accept = "application/xml;charset=UTF-8";
                StreamWriter writer = new StreamWriter(request.GetRequestStream());
                writer.WriteLine("<Invoice_Get  xmlns=\"http://www.QuickFile.co.uk\"  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"  xsi:schemaLocation=\"http://www.QuickFile.co.uk http://www.quickfile.co.uk/WebServices/API/Schemas/invoices/Invoice_Get.xsd\">< Header >< MessageType > Request </ MessageType >< SubmissionNumber > 00000001 </ SubmissionNumber >< Authentication >< AccNumber > " + QuickFile.API.accountNo + " </ AccNumber >< MD5Value > " + QuickFile.API.MD5Key + " </ MD5Value >< ApplicationID > " + QuickFile.API.appID + " </ ApplicationID ></ Authentication ></ Header >< Body >< InvoiceID > 003215 </ InvoiceID ></ Body ></ Invoice_Get > ");
                writer.Close();
                WebResponse response = default(WebResponse);
                response = request.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream());
                string XMLStringResponse = sr.ReadToEnd();

                return XMLStringResponse;

Any help will be appreciated.

The response I am getting is

    <Errors><Error>Invalid or malformed xml supplied</Error></Errors>

Hi @APereira

I’m not familiar with C#, but I’ve asked one of my colleagues who is to take a look.

In the meantime, the one thing that stands out to me is the extra spacing in the XML, e.g.
< SubmissionNumber > compared to <SubmissionNumber>

Thanks for your quick reply.

I’ve removed the extra spacing on the XML I am passing and it does not make a difference.

Still getting the same error.

Are you able to send me a private message with an example of what you’re sending please?

Hi @QFMathew

I have managed to find the issue and fix it.

Do you want me to post my code here?

I’m glad you managed to fix it! No need to post your code unless you wish to share it for other users to benefit from it.

If you do have any further issues, please don’t hesitate to ask :slight_smile:

Obviously I would like to help Anybody else with the same issue has me.

My code C# class.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Web;
using Newtonsoft.Json;

namespace MearTechAutomation
{
class QuickFile
{

    public class API : QuickFile
    {
        public static string accountNo = "XXXXXXXXXX";
        public static string appID = "xxxxxxxx-xxxx-xxxx-xxxxx-xxxxxxxx";
        public static string apiKey = "xxxxxxx-xxxx-xxxx-x";
        public static string md5Key(string SubmittionID) { string ContactenedData = QuickFile.API.accountNo + QuickFile.API.apiKey + SubmittionID;
            MD5 md5 = MD5.Create();
            byte[] inputbytes = Encoding.ASCII.GetBytes(ContactenedData); byte[] hash = md5.ComputeHash(inputbytes);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++){sb.Append(hash[i].ToString("X2"));}
            return sb.ToString().ToLower(); }
    }
    public class Invoices : QuickFile
    {
        public static string GetInvoiceDetails(int InvoiceID)
        {
            var request = (HttpWebRequest)WebRequest.Create(new Uri("https://quickfile.co.uk/WebServices/API/invoices.ashx"));
            request.Method = "POST";
            request.ContentType = "application/xml;charset=UTF-8";
            request.KeepAlive = false;
            request.Accept = "application/xml;charset=UTF-8";
            StreamWriter writer = new StreamWriter(request.GetRequestStream());
            // Generate unique submition number
            string IDSubmittion = Guid.NewGuid().ToString();
            writer.WriteLine("<Invoice_Get xmlns=\"http://www.QuickFile.co.uk\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.QuickFile.co.uk http://www.quickfile.co.uk/WebServices/API/Schemas/invoices/Invoice_Get.xsd\"><Header><MessageType>Request</MessageType><SubmissionNumber>" + IDSubmittion + "</SubmissionNumber><Authentication><AccNumber>" + QuickFile.API.accountNo + "</AccNumber><MD5Value>" + QuickFile.API.md5Key(IDSubmittion) + "</MD5Value><ApplicationID>" + QuickFile.API.appID + "</ApplicationID></Authentication></Header><Body><InvoiceID>" + InvoiceID.ToString() +  "</InvoiceID></Body></Invoice_Get>");
            writer.Close();
            WebResponse response = default(WebResponse);
            response = request.GetResponse();
            StreamReader sr = new StreamReader(response.GetResponseStream());
            string XMLStringResponse = sr.ReadToEnd();
            return XMLStringResponse;
        }
    }
}

}

2 Likes