The API usage is performed with GET and POST HTTP requests addressed to the HQ server. All requests should be authorized via authorization of type: Basic. Note that an API user must be created on the server you address.
The minimum set of tasks that the API users must be aware of to download the data includes:
- inspecting the status of a particular export file (GET request);
- requesting the re-creation of a particular export file (POST request);
- downloading a particular export file (GET request).
The format of the query is generally as follows:
[headquarters address]/api/v1/export/[export type]/[questionnaire identity]/[action]
Headquarters address is the full name of the HQ server (include the protocol), such as: https://demo.mysurvey.solutions
Export file types is one of the following supported types:
Questionnaire identity is a composite identifier of the questionnaire consisting of the GUID of the questionnaire followed by the dollar sign, followed by version index number, for example:
Action is nothing or one of the following:
Specify action start to request the export file in the corresponding format to be rebuilt on the server. Specify cancel to cancel the file rebuilding activity on the server. Specify details to obtain the status of the export data file. Specify nothing (no action at all) to download the particular data file.
Sufficient time must pass between the request to rebuild the file and a subsequent download request to allow the exported file to be created on the server. While waiting your code may periodically poll server for the updated status by submitting the details requests. The server will respond with the following JSON object:
In this case the response tells that the export file exists, but a request for it to be rebuilt has been already submitted to the server, though it hasn't started processing it yet (based on the status Queued and progress 0 percent).
The following export statuses may be encountered in Survey Solutions server responses:
- NotStarted – signals that the server hasn't been requested yet to produce an export file based on the specified questionnaire and format;
- Queued – the server has been already requested to produce an export file base on the specified questionnaire and format, but the request is waiting in queue and is not running yet;
- Running – when the server generates a new export file;
- Finished – when the sever has successfully finished producing an export file;
- FinishedWithErrors – signals that during generation of the exported file unexpected exceptions were encountered.
The attachment GetExport.zip contains a minimal C# solution that illustrates the use of the three API functions to download the export data from Survey Solutions. Note, that this is not a practical application: it does not examine the response and doesn't react to any errors (errors on the server, network errors, errors of data transmission,etc).
Use this application as a minimal example only for the API syntax demonstration.
The zip-archive of the solution contains three files for a minimal C# project:
The solution can be compiled e.g. in MS Visual Studio 2010 or later or in SharpDevelop 5.1 or later.