Api allow cross domain call?

im not able to call this api from other domains via jquery or c# Please Help

Hello @Sohaib_Ahsan

As part of the API call includes your credentials (account number, API key, and you would need to generate the MD5 too), I would highly recommend this is done from a server side script for security. If you’re using jQuery, you would need to send your data to a script (e.g. through $.post or $.ajax) and then have the script trigger the call.

C# should work without an issue, and I’m sure we have an example of code here too - I’ll see if I can find this for you.

[Edit]
There’s a C# example as part of this below post, based on the XML endpoint. However, as this post is from 2013, bear in mind some of the settings or schematics may have changed (the endpoint being one of them):

var url = “https://api.quickfile.co.uk/1_2/Report/BalanceSheet”;

[REDACTED]

///////////////
Thats ajax call that im using.but it replied with 500 Internal server error ()
Now Access-Control-Allow_Origin header is present

if I try jsonp then it says the method is not allowed

@Sohaib_Ahsan we will look into this and report back.

BTW: I removed your code sample which has some sensitive info

1 Like

Is there a reason why you want to call the API from Javascript? It’s generally not a good idea to expose sensitive credentials on the client.

This is related to the security settings of the browser. The browser disallows non-same-origin AJAX requests. It is only possible to make an AJAX call to another domain, if that domain has special CORS settings enabled to allow it. This is not something we provide on our API and recommend instead to make your calls from the server side.

ok i tried your method from c# but its also giving Error .Can you please check that again and make sure if its working ?

     HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://api.quickfile.co.uk/xml");
                req.Method = "POST";
                req.ContentType = "text/xml; encoding='utf-8'";
                req.KeepAlive = false;
             
                req.Accept = "application/xml;charset=UTF-8";
         
                StreamWriter writer = new StreamWriter(req.GetRequestStream());
                string submno = "5571a763-500c-43e6-b599-a0990081b729";
                string accno = "accno";
                string appid = "appid";
                string apikey = "apikey";
                string mds5 = CreateMD5(accno+apikey+submno);

                writer.WriteLine("<Invoice_Get  xmlns='https://api.quickfile.co.uk'  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'  xsi:schemaLocation='https://api.quickfile.co.uk https://api.quickfile.co.uk/schemas/1_2/Invoice_Create.xsd'>" +
                    "<Header> <MessageType> Request </MessageType><SubmissionNumber>" +submno+"</SubmissionNumber>" +
                   "<Authentication><AccNumber>"+accno+"</AccNumber><MD5Value>"+mds5+"</MD5Value> " +
           "<ApplicationID>"+appid+"</ApplicationID></Authentication>" +
     "</Header><Body><InvoiceID>13309</InvoiceID></Body></Invoice_Get>"); /


                writer.Close();
                WebResponse rsp = default(WebResponse);
                rsp = req.GetResponse();
                StreamReader sr = new StreamReader(rsp.GetResponseStream());
                string xmlStringResponse = sr.ReadToEnd();
                MessageBox.Show(xmlStringResponse);

its urgent for me because i need to verify invoices by connecting quickfile with our inventory system

<Invoice_Get xmlns=‘https://api.quickfile.co.uk’ xmlns:xsi=‘http://www.w3.org/2001/XMLSchema-instance’ xsi:schemaLocation=‘https://api.quickfile.co.uk https://api.quickfile.co.uk/schemas/1_2/Invoice_Create.xsd’>

In this part you’re calling Invoice_Get but referencing the schema Invoice_Create.xsd.

Are you getting a schema validation error?

thats error

3The 'https://api.quickfile.co.uk:MessageType' element has an invalid value according to its data type.

////

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(“https://api.quickfile.co.uk/xml”);
req.Method = “POST”;
req.ContentType = “text/xml; encoding=‘utf-8’”;
req.KeepAlive = false;

            req.Accept = "application/xml;charset=UTF-8";
     
            StreamWriter writer = new StreamWriter(req.GetRequestStream());
            string submno = "7a2fd4fa-69b2-4ec4-890c-8f27ec01aaf5";
            string accno = "abc";
            string appid = "abc";
            string apikey = "abc";
            string mds5 = CreateMD5(accno+apikey+submno);

            writer.WriteLine("<Invoice_Get  xmlns='https://api.quickfile.co.uk'  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'  xsi:schemaLocation='https://api.quickfile.co.uk https://api.quickfile.co.uk/schemas/1_2/Invoice_Get.xsd'>" +
                "<Header> <MessageType> Request </MessageType><SubmissionNumber>" +submno+"</SubmissionNumber>" +
               "<Authentication><AccNumber>"+accno+"</AccNumber><MD5Value>"+mds5+"</MD5Value> " +
       "<ApplicationID>"+appid+"</ApplicationID></Authentication>" +
 "</Header><Body><InvoiceID>13309</InvoiceID></Body></Invoice_Get>"); //<<<<<< INSERT YOUR XML HERE


            writer.Close();
            WebResponse rsp = default(WebResponse);
            rsp = req.GetResponse();
            StreamReader sr = new StreamReader(rsp.GetResponseStream());
            string xmlStringResponse = sr.ReadToEnd();
            Debug.WriteLine (xmlStringResponse);

I think maybe it’s due to the spaces each side of the word “Request”?

can you please try this using your account and api key so that you can confirm this and also sandbox xml is also saying

API endpoint depreciated see http://bit.ly/2xwFjSr for more details

I ran your code, closing the spaces and I got passed the schema errors.

We also know about the sandbox issue (affecting XML) and we hope to have this fixed tomorrow.

Thanks For You Help:)

1 Like

This topic was automatically closed after 7 days. New replies are no longer allowed.