I am trying to export survey responses using Google Apps Scripts using the POST API. I know I am pinging an address, but it comes back with
httpStatus":"400 - Bad Request".
My code works theoretically, but I believe its calling incorrectly and I am not sure why.
var option = {
async: true,
crossDomain: true,
url:"https://ousurvey.ca1.qualtrics.com/API/v3/surveys/SV_8dK8AKUFyAH8qyN/export-responses/",
method: "POST",
"headers": {
"X-API-TOKEN": "",
"Content-Type": "application/json",
"cache-control": "no-cache",
"Postman-Token": ""
},
processData: false,
data : '{"format":"csv"}',
muteHttpExceptions: true
};
var qUrl='https://ousurvey.ca1.qualtrics.com/API/v3/surveys/SV_8dK8AKUFyAH8qyN/export-responses/'
var getSurvey = UrlFetchApp.fetch(qUrl, option);
Currently I am just trying to pull the responses from a test survey I made, but have had no luck. I can get the two GET APIs to work by obtaining the IDs using POSTMAN, but the POST is being stubborn. I feel like I am missing something very obvious but I can't make any connections.
Page 1 / 1
@jeNguyen Never post your Tokens to a forum. I suggest editing your original post and remove them pronto.
@jeNguyen Secondly, your code is referencing two different survey IDs (you only want work with one).
@w.patrick.gale, I did not think about the API token, thank you but I'm not sure how to edit a post on here. Also I fixed the url in my code and it doesn't solve the problem unfortunately and at the moment I can't update my post to show the changes.
@jeNguyen There is a little icon that appears on the top right of the post. Click that to edit.
My current monitor made that icon near invisible, I had to squint extra hard, thank you. I also updated my code.
This is the current error I am receiving in the Google Log.
{"meta":{"httpStatus":"400 - Bad Request","error":{"errorMessage":"Error decoding json body: com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input\\n at [Source: akka.util.ByteIterator$ByteArrayIterator$$anon$1@3c9d2a4e; line: 1, column: 0]"}}}
This is the current error I am receiving in the Google Log.
{"meta":{"httpStatus":"400 - Bad Request","error":{"errorMessage":"Error decoding json body: com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input\\n at [Source: akka.util.ByteIterator$ByteArrayIterator$$anon$1@3c9d2a4e; line: 1, column: 0]"}}}
@jeNguyen,
Usually a 400 means the data you sent to the API was in the wrong format. Try removing the line feed and tab characters from the json string. Also, I think if you use single quotes, then you don't need to escape the double quotes.
```
data : '{"format":"csv"}',
```
Usually a 400 means the data you sent to the API was in the wrong format. Try removing the line feed and tab characters from the json string. Also, I think if you use single quotes, then you don't need to escape the double quotes.
```
data : '{"format":"csv"}',
```
@TomG,
I thought that was the problem as well and was fiddling with it, but I still get the same error.
I thought that was the problem as well and was fiddling with it, but I still get the same error.
I was able to figure out what was wrong with it with some help. It was mainly due to my format of the call itself:
var qUrl = "https://ousurvey.ca1.qualtrics.com/API/v3/surveys/SV_dd7ZjV7L1RX5WKh/export-responses/";
var option = {
method: "post",
headers: {"X-API-TOKEN": "JCu7bnl5ldjN9ipobqGUZj7kLO69Hklfxbr6YT9R"},
contentType: "application/json",
payload: JSON.stringify({"format": "csv"}),
muteHttpExceptions: true,
};
var qUrl = "https://ousurvey.ca1.qualtrics.com/API/v3/surveys/SV_dd7ZjV7L1RX5WKh/export-responses/";
var option = {
method: "post",
headers: {"X-API-TOKEN": "JCu7bnl5ldjN9ipobqGUZj7kLO69Hklfxbr6YT9R"},
contentType: "application/json",
payload: JSON.stringify({"format": "csv"}),
muteHttpExceptions: true,
};
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.