start_created_at not working with /collectors/{id}/responses

痴心易碎 提交于 2021-02-11 12:29:37

问题


I'm using this Google app script to query Survey Monkey results:

function surveyMonkey() {
  var token = "xxx";
  var survey = "xxx";
  var options = {"headers": {"authorization": "bearer "+token}};
  var api_key = "xxx";
  var url = 'https://api.surveymonkey.net/v3/';
  var responseURL = 'collectors/xxx/responses?api_key='+api_key
  +'&sort_by=date_modified&sort_order=DESC'
  +'&start_modified_at=2016-04-01T00:00:00+00:00'
  var responses = UrlFetchApp.fetch(url+responseURL, options);
  var responseData = JSON.parse(responses.getContentText());
  Logger.log(responseData);
}

I'm trying to call the response collector "/collectors/{id}/responses". When I exclude the query string for start_modified_at, I will get a valid JSON response. When I try to include start_modified_at, I will not get a response.

I've also tried this with just "/surveys/{id}/responses" and I'm getting the same results. It works without the date and does not work when a date is included. I've removed my own info and replaced it with xxx to share the code.

The goal is to only return responses from yesterday and append it to a spreadsheet.

This also happens with any query string that includes a date string. Are there any ideas what I might be doing wrong and how I can fix it?


回答1:


So the issue is that the + is being replaced with a space by the time it gets to our end. So it fails validation. You need to encode the URL parameters before sending them to us. So in this case the "+" will be "%2B".

Apparently Google app script is like javascript and you can solve it with encodeURIComponent('start_modified_at=2016-04-01T00:00:00+00:00').

We definitely need to work on getting you back better error messages for invalid URL parameters! Try that and let us know if you still hit issues.



来源:https://stackoverflow.com/questions/36433093/start-created-at-not-working-with-collectors-id-responses

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!