I'm using wunderlist api from Google Apps Scripts to get tasks from a list (https://developer.wunderlist.com/documentation/endpoints/task). Following code gives 'invalid request' error in the line conducting UrlFetchApp in function getTasks.
var accessToken = 'my-access-token';
var clientID = 'my-client-id';
var url = 'https://a.wunderlist.com/api/v1/';
var headers = {
'X-Access-Token': accessToken,
'X-Client-Id': clientID,
'Content-Type': 'application/json'
};
function getTasks(listId){
var payload =
{
"list_id" : listId,
"completed" : true
};
var options =
{
"method" : 'get',
"headers" : headers,
"payload" : JSON.stringify(payload),
};
var response = UrlFetchApp.fetch(url + 'tasks', options);
return response;
}
function main(){
var result = getTasks(my-listid);
}
However, doing the same thing using curl works fine;
curl -H "X-Access-Token: my-access-token" -H "X-Client-ID: my-client-id" a.wunderlist.com/api/v1/tasks?list_id=my-list-id
Utilizing another api using the same header also succeeds in Google Apps Script;
function getLists() {
var options =
{
"method" : 'GET',
"headers" : headers,
};
var response = UrlFetchApp.fetch(url + 'lists', options);
Logger.log(response);
return response;
}
function main(){
var result = getLists();
}
I wonder what is wrong in the first code. Thanks in advance!
This request is GET method. And in your curl sample,
list_id=my-list-id
is used as a query parameter. So how about this modification?Modified script :
If this didn't work, I'm sorry.