Overview

This blog is an introduction to show developers how to retrieve a list of customers from the XML API.

Refer to the XML API documentation to view a comprehensive guide with samples to programmatically communicate with the API.

Getting Started

The solution is a single-page application using HTML and jQuery to POST a request to the XML API using basic authentication.

Code Sample

The following code sample uses jQuery to send a request to the XML API that will retrieve a list of all the customers:

$.ajax
 ({
   type: "POST",
   url: "https://cortexweb/CortexAPI/Default.aspx",
   contentType: "text/xml",
   dataType: 'text',
   async: false,
   username: "cspadmin_csp",
   password: "Password123",
   data: '<?xml version="1.0" encoding="utf-8"?>' +
          '<request action="FIND" version="1.0">' +
           '<customer/>' +
          '</request>';
 });

Here is a screenshot of the request screen (request.html):

XML Request

<?xml version="1.0" encoding="utf-8"?>
<request action="FIND" version="1.0">
  <customer/>
</request>

XML Response
<?xml version="1.0" encoding="utf-8"?>
<response version="1.0">
  <customer>
    <name>CSP</name>
    <id>1</id>
    <fullname>Cortex Service Provider</fullname>
    <billingid />
    <primarydomain>csp.local</primarydomain>
    <status>Provisioned</status>
    <approvalpending>False</approvalpending>
  </customer>
  <customer>
    <name>North</name>
    <id>27</id>
    <fullname>North</fullname>
    <billingid />
    <primarydomain>north.local</primarydomain>
    <status>Provisioned</status>
    <approvalpending>False</approvalpending>
  </customer>
</response>

Download

Click here to download the single-page application.

Converting XML to JSON

If you prefer to work with JSON results instead of XML then I would suggest trying a jQuery XML to JSON plugin to covert the XML response to JSON.

For example:

.done(
  function (data) {
    var jsonData = $.xml2json(data);
});

Errors

Cross site domains

Make sure that the solution is deployed in the domain to avoid cross site domain or cross site scripting errors.   The following line was added to the code sample to enable cross domain requests:

// Enable cross-domain requests (Header: Access-Control-Allow-Origin)
$.support.cors = true;

Certificate Errors

The solution doesn’t work over SSL/HTTPS unless a valid certificate is configured for the XML API web service.

Browser Support

The solution was tested using Internet Explorer and Chrome.

If you are getting the “NetworkError: A network error occurred.” error from Chrome then try to deploy the request.html file to your API folder, such as “C:\inetpub\Cortex Management\CortexAPI”.