ForumsDevelopersPOST to API via cURL


POST to API via cURL
Author Message
sandro.krumbein

Posted: Mar 03, 2011
Score: 0 Reference
Hello,

I am trying to do a simple update of tasks by using cURL. I have come to the point that I can retrieve tasks, but now I want to edit them by doing a post

Here is my line of code from the windows commandline:
>curl http://api.toodledo.com/2/tasks/edit.php?key=myKey;f=xml -d tasks=[{"id"%3A"3917814"%2C"title"%3A"Test task 2"}]

And this is the answer:
<?xml version="1.0" encoding="UTF-8"?><tasks><error id='7'>Invalid task ID</error></tasks>

It seems that I am not completely off, but can anyone shed light on this?

Thanks,
Sandro
Jake

Toodledo Founder
Posted: Mar 03, 2011
Score: 0 Reference
The task #3917814 must not exist. Can you get tasks and see if it is there?
sandro.krumbein

Posted: Mar 05, 2011
Score: 0 Reference
Alright, despite believing to have done this before I checked this again. The task I used back then has already been deleted, but with the task #4384394 I have the same problem. Here is the entire output (almost) straight from the command line window. First retrieving details of the task and then trying to edit it

C:\Users\Administrator\Desktop\Curl + Toodledo>curl http://api.toodledo.com/2/tasks/get.php?key=myKey;fields=folder,star,priority;f=xml;id=4384394
<?xml version="1.0" encoding="UTF-8"?><tasks num='1' total='1'><task>4384394<title>Task 4</title><modified>1299318739</modified><completed>0</completed><folder>275306< /folder><priority>0</priority><star>0</star></task></tasks>
C:\Users\Administrator\Desktop\Curl + Toodledo>curl http://api.toodledo.com/2/tasks/edit.php?key=myKey;f=xml -d tasks=[{"id"%3A"4384394"%2C"title"%3A"Test task 2"}]
<?xml version="1.0" encoding="UTF-8"?><tasks><error id='7'>Invalid task ID</error></tasks>

So, yeah I believe it is there :-)


This message was edited Mar 05, 2011.
Jake

Toodledo Founder
Posted: Mar 07, 2011
Score: 0 Reference
I am not familiar with curl, so I don't know what the -d command does, but I suspect that it is not encoding the variables properly. Maybe it is double encoding them. Try doing the edit without escaping the JSON.
sandro.krumbein

Posted: Mar 09, 2011
Score: 0 Reference
Okay, this is what the cURL website says about the -d option:
Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded

Sounds reasonable to me. Or does the API insist on the application/json content-type?

I have tried leaving the message un-encoded and using the --data-urlencoded option, which is supposed to encode it itself, but to no avail either

curl http://api.toodledo.com/2/tasks/edit.php?key=myKey;f=xml --data-urlencode tasks=[{"id":"4384388","title":"Task 1 changed"}]

But maybe we can shortcut this discussion: what I am trying to do is to change the completed date of some of my tasks, which I forgot to tick off on the right day (a well known problem I guess). If you now tell me, that this isn't even possible via the API, then it's all pointless :-)

If it is possible, I still want to find a way to do it. I don't insist on cURL. I might try libCURL via C# then or something...

Thanks,
Sandro
Jake

Toodledo Founder
Posted: Mar 09, 2011
Score: 0 Reference
Yes it is possible to modify the completion data via the API. I don't know why it isn't working for you, but I still suspect that it has something to do with CURL encoding the string differently than what the API expects.
You cannot reply yet

U Back to topic home

R Post a reply

To participate in these forums, you must be signed in.