REST API: How to retrieve the interview data of a survey

Overview

SurveyToGo supports a REST API to access its data. In this how to we will cover how to use this REST API for a common use case of retrieving the interviews of a specific survey. You are welcome to adjust this code with the relevant parameters relevant to your use case to both configure the actual survey id you are using but also the different filtering parameters to only retrieve the specific subset of interviews you require.

 

Using the REST API To Retrieve Interview Data

The main functions to use when retrieving interview data are the SurveyInterviewIDs and SurveyInterviewData. The way to use them is to first request the list of interview ids that matches your search criteria and then retrieve the actual XML data for the interview IDs. Please note the SurveyInterviewData function accepts up to 99 interview id's at a time for each call. Our recommendation is to call the function with 99 interview ids and not one by one as it will speed up the data retrieval greatly. Here is a sample function in c# that shows how to call the SurveyInterviewIDs function and then loop over the interview ids in groups of 99 and call the SurveyInterviewData for each pack of interview ids:


private bool TraverseInterviewData()
{
	//-------------------------------------------
	// Setting the parameters for the calls
	//-------------------------------------------
	string surveyID = "XXXX-XXXX-XXXX-XXXX";
	string username = "RESTAPIKEY/Username";
	string password = "password";

	//------------------------------------------------------------------------------------------
	// STEP 1: Call SurveyInterviewIDs to get the interview ids of the survey (JSON format)
	//------------------------------------------------------------------------------------------
	string urlInterviewIds = string.Format(
		"https://api.dooblo.net/newapi/SurveyInterviewIDs?surveyIDs={0}",
		surveyID
	);
	RestClient client = new RestClient(urlInterviewIds);
	client.Authenticator = new HttpBasicAuthenticator(username, password);
	RestRequest request = new RestRequest();
	request.Method = Method.GET;
	client.AddDefaultHeader("Accept", "application/json");
	client.AddDefaultHeader("Accept-Charset", "utf-8");

	RestResponse resp = client.Execute(request);
	List interviewIds = JsonConvert.DeserializeObject<List>(resp.Content);

	
	//------------------------------------------------------------------------------------
	// STEP 2: Group interview IDs into groups of 99 interviews, then call the 
	//	SurveyinterviewData for each pack of 99 interviews to get the XML Data
	//	Note that the SurveyInterviewData only returns XML data, no JSON
	//------------------------------------------------------------------------------------
	int counter = 0;
	string interviewIdsInCurPack = string.Empty;
	for (int i=0; i<interviewIds.Count; i++) {
		interviewIdsInCurPack = string.Format("{0},{1}",interviewIdsInCurPack,interviewIds[i]);
		counter +=1;
		bool lastInterviewID = i==interviewIds.Count-1;
		if (counter == 99 || lastInterviewID) {
			interviewIdsInCurPack = interviewIdsInCurPack.Remove(0,1);
			string urlInterviewData = string.Format(
				"https://api.dooblo.net/newapi/SurveyInterviewData?subjectIDs={0}&surveyID={1}&onlyHeaders=false&includeNulls=false",
				interviewIdsInCurPack,
				surveyID
			);
			client = new RestClient(urlInterviewData);
			client.Authenticator = new HttpBasicAuthenticator(username, password);
			request = new RestRequest();
			request.Method = Method.GET;
			client.AddDefaultHeader("Accept", "text/xml");
			client.AddDefaultHeader("Accept-Charset", "utf-8");
			resp = client.Execute(request);
					
			//------------------------------------------------------------------------------------
			// STEP 3: This is the actual XML Data as it comes as an answer, your code should 
			//	process xmlInterviewData to process the interview data of the 99 interviews of 
			//	this pack
			//------------------------------------------------------------------------------------
			string xmlInterviewData = resp.Content.ToString();
			......
			......
			......

			counter = 0;
			interviewIdsInCurPack = string.Empty;
		}
		if (lastInterviewID) {
			break;
		}
	}
	return true;
}

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.