I'm trying to create a task in todoist but cant seem to do so
According to this todoist documentation, the below should work for creating a todoist task
$ curl https://todoist.com/api/v7/sync \
-d token=0123456789abcdef0123456789abcdef01234567 \
-d sync_token="VRyFHr0Qo3Hr--pzINyT6nax4vW7X2YG5RQlw3lB-6eYOPbSZVJepa62EVhO" \
-d resource_types='["projects", "items"]' \
-d commands='[
{ "type": "item_add",
"temp_id": "fdef5d16-a40a-475e-bd4a-0ccbd6fd8c3f",
"uuid": "a3aa2f44-23b4-4986-b513-ef7663bbb752",
"args": { "project_id": "24a193a7-46f7-4314-b984-27b707bd2331", "content": "Task1" } },
{ "type": "item_add",
"temp_id": "6f5e0b50-af7a-4133-bfc0-e8c041b819d2",
"uuid": "d16ad84a-e10b-4894-af7d-93ba6adf7a1e",
"args": { "project_id": 176637191, "content": "Task2" } },
]'
I've tried the following with little luck
commands = [{"type": "item_add", "uuid": "a3aa2f44-23b4-4986-b513-ef7663bbb752", "args": {"project_id": 2159935681,"content":"Test Task"}}]
$.ajax({
type: "GET",
url: 'https://en.todoist.com/api/v7/sync/',
dataType: 'json',
async: false,
data: {
'token': todoist_api_token,
'sync_token':'*',
'resource_types':'["projects", "items"]',
'commands':commands
}
})
I've also tried the following:
commands = [{"type": "item_add", "uuid": "a3aa2f44-23b4-4986-b513-ef7663bbb752", "args": {"project_id": 2159935681,"content":"Test Task"}}]
$.ajax({
type: "POST",
url: 'https://en.todoist.com/api/v7/sync/',
dataType: 'json',
async: false,
data: {
'token': todoist_api_token,
'sync_token':'*',
'resource_types':'["projects", "items"]',
'commands':commands
}
})
This results in the following error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://en.todoist.com/api/v7/sync/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
I've also tried removing the project id
commands = [{"type": "item_add", "uuid": "a3aa2f44-23b4-4986-b513-ef7663bbb752", "args": {"content":"Test Task"}}]
$.ajax({
type: "GET",
url: 'https://en.todoist.com/api/v7/sync/',
dataType: 'json',
async: false,
data: {
'token': todoist_api_token,
'sync_token':'*',
'resource_types':'["items"]',
'commands':commands
}
})
I've also tried adding the temp_id parameter:
commands = [{"type": "item_add","temp_id": "fdef5d16-a40a-475e-bd4a-0ccbd6fd8c3f", "uuid": "a3aa2f44-23b4-4986-b513-ef7663bbb752", "args": {"project_id": 2159896038,"content":"Test Task"}}]
$.ajax({
type: "POST",
url: 'https://en.todoist.com/api/v7/sync/',
dataType: 'json',
async: false,
data: {
'token': todoist_api_token,
'sync_token':'*',
'resource_types':'["projects", "items"]',
'commands':commands
}
})
I've even tried the todoist api v8 version following the todoist instrucitons for the v8 api here
$.ajax({type: "POST",
url: 'https://beta.todoist.com/API/v8/tasks',
dataType: 'json',
async: false,
data: {'token':todoist_api_token,'content': 'Appointment with Maria'}
});
This returns "Bad Request"
I did find that the following works for v6:
$.ajax({type: "POST",
url: 'https://todoist.com/API/v6/add_item',
dataType: 'json',
async: false,
data: {'token':todoist_api_token,'content': 'Appointment with Maria'}
});