Skip to content

Instantly share code, notes, and snippets.

@mopa
Last active August 25, 2023 11:33
Show Gist options
  • Save mopa/2ce91d716c5e77fa813150efda3c45e2 to your computer and use it in GitHub Desktop.
Save mopa/2ce91d716c5e77fa813150efda3c45e2 to your computer and use it in GitHub Desktop.
A simple bookmarklet to send the current web page to Todoist
javascript:(function() {
const token = 'TOKEN_ID';
const url = window.location.href;
const title = document.title;
const content = `[${title}](${url})`;
const data = {
'content': content,
'project_id': PROJECT_ID // Only if you want to send to specific project
};
fetch('https://api.todoist.com/rest/v2/tasks', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Request-Id': `${Math.random()}`,
'Authorization': `Bearer ${token}`
},
body: JSON.stringify(data)
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => console.log(data))
.catch((error) => {
console.error('Error:', error);
alert(`An error occurred: ${error.message}`);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment