I've got a survey in Qualtrics, and a game created in Unity that would capture responses to those survey questions. What I'm trying to do is to upload the captured responses directly from Unity to Qualtrics, however, I'm having trouble figuring out what I'm doing wrong in the api request.
https://api.qualtrics.com/docs/survey-response-import-guide
I'm able to get a "success" response from the server, but my data isn't getting uploaded.
Here's the code snippet from Unity:
byte[] results;
WWWForm form = new WWWForm();
UnityWebRequest www = UnityWebRequest.Get(getPath());
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log(www.downloadHandler.text);
results = www.downloadHandler.data;
form.AddBinaryData("fileUpload", results, "csvUpload.png", "text/csv; charset=UTF-8");
}
UnityWebRequest qualtricsUpload = UnityWebRequest.Post("<server link redacted>", form);
qualtricsUpload.SetRequestHeader("X-API-TOKEN", "<api token redacted>");
qualtricsUpload.SetRequestHeader("Content-Type", "text/csv; charset=UTF-8");
yield return qualtricsUpload.SendWebRequest();
if (qualtricsUpload.isNetworkError || qualtricsUpload.isHttpError)
{
Debug.Log(qualtricsUpload.error);
}
else
{
Debug.Log("Survey Responses Uploaded!");
}
I'm not getting any errors whatsoever, but nothing is getting uploaded. I suspect it's something to do with file formatting or the way I'm posting it, but I am pretty stumped. My file format is exactly as their guide above suggests (except based on my survey), formatting looks fine in Excel as well. The strange thing is, when i previously forgot to send the "get" request for the file, and assigned results to (what i assume would be a null object) and sent that to the Qualtrics server, it actually submitted a blank response to the survey. So the api request is definitely working (in some way at least), but I cant seem to send actual data.
Anyone else have experience with this or have ideas?