Setting up my first survey automation via API | XM Community
Solved

Setting up my first survey automation via API

  • 28 August 2018
  • 2 replies
  • 259 views

Userlevel 7
Badge +6
Hello community!

I have never done anything with an API and would even call my programming skills as "light" by most standards. With that said, I am very interested in trying to automate a survey using the Qualtrics API. Having never done this, I am not sure of the process, pitfalls, best practices, etc. Who has already done this and what program(s) did you use? How does it all work together.

Below are my thoughts and I welcome any helpful input anyone has. If I am missing something or am way off base, please let me know.

1. A .csv distribution file will exist somewhere on a regular schedule. It would be ideal if this "somewhere" could be a local drive, but every other automation I have seen uses an SFTP. Is it possible to even use a local drive to point to as part of the API call?
2. I program a script that calls the Qualtrics API and distributes the appropriate email, survey, etc. to the above distribution list. My org is pretty SAS heavy so that is likely what I will try to use unless there is a much better option.
3. I use windows task scheduler to trigger the SAS code on a regular cadence.
4. At this point I am done as the scope of my first program job would be to just automate the distribution and not do anything about pulling the results back.
icon

Best answer by TomG 29 August 2018, 16:14

View original

2 replies

Userlevel 7
Badge +27
@Akdashboard,

Most people do this sort of automation using a web server and it seems like you plan on using a Windows workstation.
1. You have to use the old API (v2.5) in order to upload a csv. Either the csv has to be accessible by url or you have to include the data in the API call (but there really isn't any documentation on how to do this - just a brief mention that it is an option). With v3.0 you have to convert the csv to json first, and like v2.5 it has to be accessible via url or you can include it in the API call. If you include it in the API call the size is limited (I think it is 5MB).
2. SAS seems like an unusual choice, but its been many years since I've used it so I can't really comment on how well it would work. Most people would use a web scripting language like php or python.
3. Seems fine. On an Apache web server cron would be used.
​Hurray - SAS Programmers 🙂

Here's is an example of what I did to automate getting survey data. It's a translation of the Python script. The other APIs are less complex than this one (at least the ones I use), so if you get this working you're good to go. I'm using SAS9.4M5 in Linux but the syntax should be real close on Windows. Hope this helps!

Here is an example of a complex API transaction using SAS and PROC HTTP

/*POST A REQUEST FOR SURVEY DATA*/
/****************************************************************************/
/* Qualtrics API Request to get export of survey response data
/* To compare to Python go to https://api.qualtrics.com/docs/response-exports
/****************************************************************************/
filename rsp temp;
proc http
url="https://yourdatacenter.qualtrics.com/API/v3/responseexports/"
method= "POST"
in='{"format" : "csv","surveyId" : "yoursurveyID"}'
out=rsp;
headers
"X-API-Token"="yourAPItoken"
"Content-Type"="application/json"
;
run;
libname RSP JSON fileref=rsp;

/*Check Status of request*/
filename dwnld temp;
proc http
url="https://yourdatacenter.qualtrics.com/API/v3/responseexports/yourresultID" /*Check json from rsp for result*/
method= "GET"
out=dwnld;
headers
"X-API-Token"="yourAPItoken";
run;
libname dwnld JSON fileref=dwnld;

/*Download request - You can view json dwnld for status and filename (same as yourresultID above)*/
filename dwnld '/yourPathHere/GOTDATA';
proc http
url="https://yourdatacenter.qualtrics.com/API/v3/responseexports/yourresultID/file"
method= "GET"
out=dwnld;
headers
"X-API-Token"="youAPItoken";
run;

Leave a Reply