• I’m using a workflow in pipedream that will update my google tasks lists when I update my tasks in notion. (I’m using Thomas Frank’s Ultimate Brain for reference). It consists of these elements
a. A Notion trigger named “Updated Page in Database” emits an event when a page in your Notion database is updated.
b. A Google Tasks action named “list_tasks” retrieves the tasks from your Google Tasks list.
c. A Google Tasks API code that updates each task’s due date, notes, and completion status in the tasks array obtained from the “list_tasks” step. It also should create a task if one doesn’t exist in Google Tasks
◦ I also use reclaim.ai’s Google task integration. It removes anything in parenthesis from the title of the task after it’s imported into Google Tasks, so an exact match of the title won’t work.
This is the code I’m using
import { axios } from "@pipedream/platform";
export default {
props: {
google_tasks: {
type: "app",
app: "google_tasks",
},
task_list_id: {
type: "string",
label: "Task List ID",
default: "Mk1hZng3dVdLeEJ6ZVZqUg", // Replace with your default task list ID
},
notion_due_date: {
type: "string",
label: "Notion Due Date",
},
notion_page_url: {
type: "string",
label: "Notes",
},
notion_task_title: {
type: "string",
label: "Notion Task Title",
},
},
async run({ steps, $ }) {
try {
console.log("Starting the component...");
// Log input values for debugging
console.log("Notion Task Title:", this.notion_task_title);
console.log("Notion Due Date:", this.notion_due_date);
console.log("Notion Page URL:", this.notion_page_url);
const taskDueDate = new Date(this.notion_due_date);
if (isNaN(taskDueDate.getTime())) {
console.error("Invalid date value:", this.notion_due_date);
} else {
const isoDueDate = taskDueDate.toISOString();
console.log("ISO Due Date:", isoDueDate);
// Debugging: Log HTTP request to Google Tasks API
console.log("HTTP Request to Google Tasks API:", {
method: "GET",
url: `https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks`,
headers: {
Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`,
},
});
const response = await axios(this, {
method: "GET",
url: `https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks`,
headers: {
Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`,
},
});
// Check if the response exists
if (response && response.data) {
console.log("Google Tasks Response:", response.data);
const tasksArray = response.data.items;
// Debugging: Log the tasks obtained from Google Tasks
console.log("Tasks from Google Tasks:", tasksArray);
// Check if there is an existing task with a matching title
const partialNotionTaskTitle = this.notion_task_title.substring(0, 6); // Change 6 to the desired length
const matchingTask = tasksArray.find((task) => {
const taskTitle = task.title || "";
return taskTitle.startsWith(partialNotionTaskTitle);
});
if (matchingTask) {
// Task already exists, update it
const taskId = matchingTask.id;
// Check if the task in Notion is marked as completed
const notionTaskCompleted = steps.trigger.event.properties.done.checkbox;
// Debugging: Log the Notion completion status
console.log("Notion Task Completed:", notionTaskCompleted);
// Update the task in Google Tasks based on Notion completion status
const googleTaskStatus = notionTaskCompleted ? "completed" : "needsAction";
try {
const response = await axios(this, {
method: "PATCH",
url: `https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks/${taskId}`,
headers: {
Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`,
"Content-Type": "application/json",
},
data: {
due: isoDueDate,
notes: this.notion_page_url,
status: googleTaskStatus,
},
});
console.log("Update response:", response.data);
} catch (error) {
console.error("Error updating task:", taskId, error.response ? error.response.data : error);
}
} else {
console.log("Matching task not found in Google Tasks. Creating a new task...");
// Create a new task in Google Tasks
const newTask = {
title: this.notion_task_title,
due: isoDueDate,
notes: this.notion_page_url,
};
const createResponse = await axios(this, {
method: "POST",
url: `https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks`,
headers: {
Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`,
"Content-Type": "application/json",
},
data: newTask,
});
console.log("New task created:", createResponse.data);
}
} else {
console.log("Google Tasks Response is empty.");
}
}
console.log("Completed the component successfully.");
} catch (error) {
console.error("Error in the component:", error);
}
},
};