Creating Task using Wunderlist API

7.7k Views Asked by At

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

There are 1 best solutions below

0
On BEST ANSWER

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.