Creating Task using Wunderlist API

对着背影说爱祢 提交于 2020-01-06 03:34:08

问题


After understanding this (guess so) and ended up using the Wunderlist API, it worked for listing all my lists and listing all my tasks with a given list_id. Now i'm trying to create a task, given a list_id:

function create_new_task(){
   list_id = $("#list_id").val(); //Checked for an integer
   title = $("#task_title").val(); //Checked for a string
   $.ajax({
       url: 'https://a.wunderlist.com/api/v1/tasks',
       method: 'POST',
       contentType: 'application/json',
       headers: { 'X-Access-Token': access_token, 'X-Client-ID': client_id },
       data: {"list_id": parseInt(list_id), "title": title.toString() }
   }).success(function(data){
       $("#create_new_task_modal").modal('hide');
       swal("Task created!", "Your task was successfully created!", "success");
   }).error(handleError);
}

But im getting a 400 bad request with the following non-descriptive error:

{"error":"bad_request"}

Any one has accomplished this before or can see what am i missing?

Thanks!

Update:

Now im trying to use CURL and it works.. cant find the difference with my $.ajax implementation:

curl -H "Content-Type: application/json" -H "X-Access-Token: XXX" -H "X-Client-ID: YYY" a.wunderlist.com/api/v1/tasks -X POST -d '{"list_id":1234567,"title":"hellooo"}'

回答1:


Finally!, this did the trick.

Apparently i had to set processData: false because i needed to send a string as data, not an object. Also changing data to a string instead of an object.



来源:https://stackoverflow.com/questions/30992688/creating-task-using-wunderlist-api

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