mytinytodo icon indicating copy to clipboard operation
mytinytodo copied to clipboard

Add a new task via curl

Open Justinzobel opened this issue 4 years ago • 10 comments

Add a new task via curl e.g.

curl http://myhost/add?list=personal?task="My new task"

Justinzobel avatar Jul 03 '21 02:07 Justinzobel

As for now you can use

curl \
--data-urlencode "list=1" \
--data-urlencode "title=/+1/ Task with spaces /Tag1, Tag2/" \
"http://localhost/mytinytodo/ajax.php?newTask" 

This command will add a task to list with ID = 1: title: Task with spaces priority: +1 tags: Tag1, Tag2

Settings: v1.6.x. No password is set. Smart syntax is enabled.

maxpozdeev avatar Jul 09 '21 10:07 maxpozdeev

This works great! Thank you.

Justinzobel avatar Jul 10 '21 05:07 Justinzobel

I'm going to comment on this one as it's related.

Is it possible to add an automatic refresh option when a new task is added via curl or simply on a timer?

Context: I'm scripting the addition of tasks when something happens on my servers that I need to attend to and I have MyTinyTodo on my status page now. This would allow me to see critical (Prio +2) issues asap and respond to them.

Justinzobel avatar Jul 10 '21 05:07 Justinzobel

Hello, can you help me understand how to interact with API?

I wanna post new tasks via curl, but as I understand, I need to authenticate, because without it I always get response 403 when I post to .../api.php?_path=/lists with mtt-token, which I get from .../api.php?_path=/session

{
  "total": 0,
  "list": [],
  "denied": 1
}

So, first I make POST to .../api.php?_path=/session and get mtt-token Next I make POST to .../api.php?_path=/login with header mtt-token *** and JsonBody with my password password *** but always get response 200

{
  "logged": 0
}

Thank you!

kekwkappa avatar Sep 25 '23 14:09 kekwkappa

In v1.7 http api was changed.

  1. Get session id and token for login:

curl -X POST "test:8080/api.php?_path=/session"

returns

{
  "session": "rhon8fisk5dj4pmtc9hrbeddge",
  "token": "4d4d8110-1fd6-42f3-a507-eea46d24512a"
}
  1. Login with password as well as token and session id from step 1. You'll get new token for further requests. Session id will be the same.
curl "test:8080/api.php?_path=/login" \
  --header "Content-Type: application/json" \
  --header "MTT-Token: 4d4d8110-1fd6-42f3-a507-eea46d24512a" \
  --header "Cookie: mtt-session=rhon8fisk5dj4pmtc9hrbeddge" \
  --data '{"password":"foo"}'

returns

{
  "logged": 1,
  "token": "6e72c91f-99e4-4968-b6f6-72161441b9c7"
}
  1. Create task. Pass token from step 2 and session id from step 1.
curl "test:8080/api.php?_path=/tasks" \
  --header "Content-Type: application/json" \
  --header "MTT-Token: 6e72c91f-99e4-4968-b6f6-72161441b9c7" \
  --header "Cookie: mtt-session=rhon8fisk5dj4pmtc9hrbeddge" \
  --data '{"list":44, "title":"+1 Task with spaces #Tag1 #Tag2"}'

returns

{
  "total": 1,
  "list": [...]
  }
}

maxpozdeev avatar Sep 25 '23 14:09 maxpozdeev

Thank you for help!

kekwkappa avatar Sep 25 '23 18:09 kekwkappa

@maxpozdeev Did the API change for 1.8? When I try:

curl -X POST "https://my.domain.com/api.php?_path=/session"

it returns:

{"disabled":1}%

No password is set and Smart Syntax is enabled.

s22-tech avatar Jan 04 '24 18:01 s22-tech

@s22-tech No API changed in 1.8. You need to set password.

maxpozdeev avatar Jan 08 '24 12:01 maxpozdeev

O.K. That makes the api work. However, I don't want to have to login when I access the site via the browser. Is there a way to have the password only affect the api?

s22-tech avatar Jan 08 '24 16:01 s22-tech

Without password you don't need to call "/session" and "/login" api endpoints. Just do request with some random identifier passed in MTT-Token header and mtt-token cookie (both the same).

curl "test:8080/api.php?_path=/tasks" \
  --header "Content-Type: application/json" \
  --header "MTT-Token: some-string" \
  --header "Cookie: mtt-token=some-string" \
  --data '{"list":44, "title":"+1 Task with spaces #Tag1 #Tag2 @monday"}'

maxpozdeev avatar Jan 09 '24 18:01 maxpozdeev