First steps with AskiaVista 6.0 API
To download the example files, click here
Introduction
AskiaVista SDK (Software Development Kit) is now using new web technologies to perform cross-tabs using AJAX requests. This allows you to embed result tables and charts within an existing HTML page.
Our AskiaVista AJAX library, distributed under the AskiaVistaSDK license, is based on jQuery which is an open-source (MIT License) and pretty nice AJAX framework.
The jQuery framework is easy to learn, easy to understand and has a large community of developers and resources.
The server-side AJAX requests are managed by the AskiaVistaReader application, which is an AskiaVista component. So the requirement is a complete installation of AskiaVista+AskiaVistaReader on an IIS server, here you can find more details about the minimum requirements for AskiaVista installation.
AskiaVista AJAX – Setting up your page
In the html page First_API_Page.html attached you will find the following pieces of code:
1. Script calls you need to access the API.
2. Authentication.
3. The table definition (this one is the code from Vista6 interface).
Script calls
In order to make the AJAX calls, the AJAX libraries must be declared in the head section of your page using the following piece of code:
<script type="text/javascript" src="http://my.example.com/AskiaVistaReader.Net4/Scripts/jquery.js"></script>
<script type="text/javascript" src="http://my.example.com/AskiaVistaReader.Net4/Scripts/askiavista.js"></script>
Line 1 includes the jQuery core library into your page.
Line 2 includes the AskiaVista AJAX core library into your page.
Authentication
AskiaVista AJAX Framework offers different mode of the authentication with different type of security levels. You can find more information about Authentication in AskiaVista AJAX Framework:
http://www.askia.com/Downloads/dev/docs/AskiaVistaAJAX/index.html#!/guide/authentication
In the example attached, I use implicit authentication using the authenticityToken.
This code below is for the authentication:
askiaVista.config({ url: "http://show.askia.com/AskiaVistaReader.Net4/AjaxEmbedHandler.aspx", authenticityToken: "30a70ab6-6cd3-4823-815a-42df2b98b7e9", survey: "EX" });
The authenticityToken is a random unique key assign to each user. This key can be found and regenerated in the AskiaVista administration (View-> Administration mode -> Users -> User General tab as per the image below):
Table definition
The code below is the source code from AskiaVista6, the only thing that needs to be changed is the containerID where the default value "YOUR_CONTAINER_ID" needs to be updated with the ID of the HTML element where the table is going to be placed, in the example provided <div id="result"></div>:
askiaVista.getPages({ "settings": { "id": 81 }, "tabStyle": 18, "title": "??C?? x ??R??", "rows": [ { "key": "1|29@@0", "shortcut": "7. Type" } ], "columns": [ { "key": "1|10@@0", "shortcut": "i1. Gender" } ], "survey": { "id": 1, "name": "EX" }, "containerId": "result" });
Other examples
Since version 6.0, AskiaVista provides access to the Highcharts charting library. For the example “Chart_highchart.html” I have added the script calls for Highcharts. The source code for the chart itself has been taken from the source code button in vista 6 as well.
In the file attached you can find also 3 other examples:
- Chart_google_API .html that uses google API pie chart.
- DynamicCrossTab.html that displays a table and 3 drop down menus with the filters, weighting and profiles created in Vista for the EX survey.
- GetInterviews.html that displays the raw data for few questions.
For more documentation about the API.
Running the html pages locally
To be able to test this pages locally and use server side scripts on your computer you will need to set up a local web server.
1. Set up a local web server (e.g. IIS, you can find information here: http://www.iis.net/).
2. Once your local web server is set up you will be able to access http://localhost (you can find information here).
3. Copy the html pages you have previously downloaded to the root of your local server (For IIS C:\inetpub\wwwroot\).
4. Open your index.html file (via the HTTP protocol) in your browser: you should end up with a URL such as http://localhost/First_API_Page.html.
Vista6 source code option
Vista 6 has now the functionality to retrieve the source code of a table/chart. This option needs to be enabled in Vista5 admin mode, administrator view -> authorisations -> AskiaVista Version 6 -> select “Raw data”.
Once the option is available you will be able to see the button “source code” on the result area of AskiaVista (see image below).
I have used that piece of code for the first example “First_API_Page.html”.