Create Response Export (API v3) to CSV for data mapping | XM Community

Create Response Export (API v3) to CSV for data mapping

  • 27 May 2019
  • 1 reply
  • 283 views

Userlevel 5
Badge +13
I finally learned you can use the Create Response Export to csv format as a data map of the the newer response variables (like those text field variables with _TEXT appended to them that do not appear in the .qsf file or the Get Survey API call). For my data mapping process I make API calls to retrieve the survey information of all of my surveys using the Get Survey API call (https://api.qualtrics.com/reference#get-survey) and save these JSON files locally. I then make another set of API calls of all my surveys to get the data variable mapping using the Create Response Export to csv (https://api.qualtrics.com/reference#create-response-export-new) using a limit=1 to only get the bare minimum header data, then parse that into a json file for each survey and save these files locally as well. I can then make normal Create Response Export (format=json) API calls to get the response data that can then be mapped using the locally saved variable mapping json files. This is how I began the transition from the older API response calls (which had a different data formatting/structure) to the newer API response data.

NOTE:
When using the Create Response Export to csv format API call, I learned the 'newlineReplacement' parameter actually refers to any new lines present in your survey question labels (which will cause problems parsing your CSV data unless you remove them). I set this parameter to a blank space
(newlineReplacement=' ') in my API calls to correct the line break issues I was having, and I would suggest always setting this parameter to a blank space or similar when pulling CSV formatted responses to prevent unwanted line breaks in the data.

1 reply

Userlevel 5
Badge +13
Here is some PHP to create a very simple map between your defined QIDs and the variable IDs defined in the new API response export:

// break the CSV survey response data $surveyCsvResponseExport (this is the CSV data pulled from the zip file of the Response Export API call) into an array
$surveyCsvResponseExportArray = array_map("str_getcsv", explode("\\n", $surveyCsvResponseExport));
$dataMapArray = array(); // create a placeholder array to store your data map
// for each value in the first row of the CSV (which are your defined survey QIDs)
foreach($surveyCsvResponseExportArray[0] as $key=>$val) {
// get the ImportId value (the 'newer' variable name from the response export of the API)
$json = json_decode($surveyCsvResponseExportArray[2][$key]);
// foreach of your defined variable names, map the new ImportId to it
$dataMapArray[$val] = $json->{'ImportId'};
}
// json encode your final array
$jsonEncode = json_encode($dataMapArray);

The end result will look something like the following with your defined variable name (as the key) and the API response export variable name (as the value):

{"StartDate":"startDate","EndDate":"endDate","Status":"status","IPAddress":"ipAddress","Progress":"progress"}

Leave a Reply