On 7/23/21 11:11 AM, bachmeier wrote:
I'm writing a D program that interacts with the Todoist API using
std.net.curl. It's not a problem to do get requests to query tasks, but
I cannot find a way to get post to work to create a new task.
This is a working bash script, where APIKEY is defined elsewhere and $1
and $2 are user input when running the script:
```
curl "https://api.todoist.com/rest/v1/tasks" -X POST --data
"{"'"'"content"'"'": "'"'"$1"'"'", "'"'"project_id"'"'": $2}" -H
"Content-Type: application/json" -H "Authorization: Bearer $APIKEY"
```
(For obvious reasons I'm not going to provide a working example.) How
can I translate this into a post function call within D?
[Todoist API
Reference](https://developer.todoist.com/rest/v1/?shell#create-a-new-task)
I haven't used it but isn't it the version of post that takes a
dictionary here?
https://dlang.org/phobos/std_net_curl.html#.post
If the Authorization is the problem, I wonder whether addRequestHeader
is the solution:
https://dlang.org/phobos/std_net_curl.html#.HTTP.addRequestHeader
Ali