使用Wunderlist API创建任务

问题描述 投票:1回答:1

在理解了this(猜测如此)并最终使用Wunderlist API后,它可以列出我的所有列表,并列出给定list_id的所有任务。现在我正在尝试创建一个任务,给定一个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);
}

但我得到一个400 bad request与以下非描述性错误:

{"error":"bad_request"}

任何人之前已经完成了这项工作,或者可以看到我错过了什么?

谢谢!

更新:

现在我试图使用CURL,它工作..无法找到我的$ .ajax实现的差异:

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"}'
ajax json api rest wunderlist
1个回答
1
投票

终于!,this做了这个伎俩。

显然我必须设置processData: false因为我需要发送一个字符串作为数据,而不是一个对象。还将数据更改为字符串而不是对象。

© www.soinside.com 2019 - 2024. All rights reserved.