It seems like the code you provided is only updating the existing tasks in Google Tasks, but not creating a new task if it doesn’t exist. To create a new task when it’s not found in Google Tasks, you can add the following code snippet after the if (tasksArray && tasksArray.length > 0) block: } else { // Create a new task if it doesn't exist in Google Tasks try { const response = 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: { title: "Your Task Title", // Replace with the task title from Notion due: isoDueDate, notes: this.notion_page_url, status: "completed", }, }); console.log("New task created:", response.data); } catch (error) { console.error("Error creating new task:", error.response ? error.response.data : error); } } Make sure to replace "Your Task Title" with the appropriate task title from the Notion data. This code will create a new task in Google Tasks when it’s not found in the existing tasks.
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 Notion trigger named “Updated Page in Database” that emits an event when a page in your Notion database is updated.
- A Google Tasks action named “list_tasks” retrieves the tasks from your Google Tasks list.
- 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.
The problem is that the code keeps creating new tasks whenever I complete a task in Notion. I’m not sure what I’m doing wrong in the code. Here’s the code: 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”,
},
notion_due_date: {
type: “string”,
label: “Notion Due Date”,
},
notion_page_url: {
type: “string”,
label: “Notes”,
},
},
async run({ steps, $ }) {
try {
console.log(“Starting the component…”);
const taskDueDate = new Date(this.notion_due_date);
if (isNaN(taskDueDate.getTime())) {
console.error("Invalid date value");
} else {
const isoDueDate = taskDueDate.toISOString();
// 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}`,
},
});
if (response.data) {
console.log("Google Tasks Response:", response.data);
const tasksArray = response.data.items;
if (tasksArray && tasksArray.length > 0) {
const updateTasksPromises = tasksArray.map(async (task) => {
console.log("Task:", task);
const taskId = task.id;
// Check if the task in Notion is marked as completed
const notionTaskCompleted = steps.trigger.event.properties.done.checkbox;
// 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);
}
});
await Promise.all(updateTasksPromises);
}
} else {
console.log("Google Tasks Response is empty. Creating a new task...");
// Create a new task in Google Tasks
const newTask = {
title: (steps.trigger.event.properties.Task.title[0].plain_text),
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);
}
}
console.log("Completed the component successfully.");
} catch (error) {
console.error("Error in the component:", error);
}
},
};
I see that the code you provided is trying to update the tasks in Google Tasks based on the information from Notion. However, it seems like the code is not checking if the task already exists in Google Tasks before creating a new one. This might be the reason why it keeps creating new tasks whenever you complete a task in Notion. To fix this issue, you can modify the code to check if a task with the same title already exists in Google Tasks before creating a new one. Here’s an updated version of your code with this change: ``` 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”, }, notion_due_date: { type: “string”, label: “Notion Due Date”, }, notion_page_url: { type: “string”, label: “Notes”, }, }, async run({ steps, $ }) { try { console.log(“Starting the component…”); const taskDueDate = new Date(this.notion_due_date); if (isNaN(taskDueDate.getTime())) { console.error(“Invalid date value”); } else { const isoDueDate = taskDueDate.toISOString(); 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}, }, }); if (response.data) { console.log(“Google Tasks Response:”, response.data); const tasksArray = response.data.items; const notionTaskTitle = steps.trigger.event.properties.Task.title[0].plain_text; const existingTask = tasksArray.find(task => task.title === notionTaskTitle); if (existingTask) { // Update the existing task const taskId = existingTask.id; const notionTaskCompleted = steps.trigger.event.properties.done.checkbox; const googleTaskStatus = notionTaskCompleted ? “completed” : “needsAction”; try { const response = await axios(this, { method:
I think your code was cut off
Apologies for that. Here’s the complete updated code to check if a task with the same title already exists in Google Tasks before creating a new one: ``` import { axios } from “@pipedream/platform”; export default { props: { google_tasks: { type: “app”, app: “google_tasks”, }, task_list_id: { type: “string”, label: “Task List ID”, }, notion_due_date: { type: “string”, label: “Notion Due Date”, }, notion_page_url: { type: “string”, label: “Notes”, }, }, async run({ steps, $ }) { try { console.log(“Starting the component…”); const taskDueDate = new Date(this.notion_due_date); if (isNaN(taskDueDate.getTime())) { console.error(“Invalid date value”); } else { const isoDueDate = taskDueDate.toISOString(); 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}, }, }); if (response.data) { console.log(“Google Tasks Response:”, response.data); const tasksArray = response.data.items; const notionTaskTitle = steps.trigger.event.properties.Task.title[0].plain_text; const existingTask = tasksArray.find(task => task.title === notionTaskTitle); if (existingTask) { // Update the existing task const taskId = existingTask.id; const notionTaskCompleted = steps.trigger.event.properties.done.checkbox; const googleTaskStatus = notionTaskCompleted ? “completed” : “needsAction”; try { const response = await axios(this, { method: “PUT”, 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: { status: googleTaskStatus, due: isoDueDate, notes: this.notion_page_url, }, }); console.log(“Task updated:”, response.data); } catch (error) {
are you sure? The code looks unfinished at the end?
Apologies for the incomplete code earlier. Here’s the complete updated code to check if a task with the same title already exists in Google Tasks before creating a new one: ``` import { axios } from “@pipedream/platform”; export default { props: { google_tasks: { type: “app”, app: “google_tasks”, }, task_list_id: { type: “string”, label: “Task List ID”, }, notion_due_date: { type: “string”, label: “Notion Due Date”, }, notion_page_url: { type: “string”, label: “Notes”, }, }, async run({ steps, $ }) { try { console.log(“Starting the component…”); const taskDueDate = new Date(this.notion_due_date); if (isNaN(taskDueDate.getTime())) { console.error(“Invalid date value”); } else { const isoDueDate = taskDueDate.toISOString(); 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}, }, }); if (response.data) { console.log(“Google Tasks Response:”, response.data); const tasksArray = response.data.items; const notionTaskTitle = steps.trigger.event.properties.Task.title[0].plain_text; const existingTask = tasksArray.find(task => task.title === notionTaskTitle); if (existingTask) { // Update the existing task const taskId = existingTask.id; const notionTaskCompleted = steps.trigger.event.properties.done.checkbox; const googleTaskStatus = notionTaskCompleted ? “completed” : “needsAction”; try { const response = await axios(this, { method: “PUT”, 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: { status: googleTaskStatus, due: isoDueDate, notes: this.notion_page_url, }, }); console.log(“Task updated:”, response.data); } catch (
It really doesn’t look complete. Can you put the code in a code block?
I apologize for the confusion earlier. Here’s the complete code for checking if a task with the same title already exists in Google Tasks before creating a new one, formatted in a code block: ``` import { axios } from “@pipedream/platform”; export default { props: { google_tasks: { type: “app”, app: “google_tasks”, }, task_list_id: { type: “string”, label: “Task List ID”, }, notion_due_date: { type: “string”, label: “Notion Due Date”, }, notion_page_url: { type: “string”, label: “Notes”, }, }, async run({ steps, $ }) { try { console.log(“Starting the component…”); const taskDueDate = new Date(this.notion_due_date); if (isNaN(taskDueDate.getTime())) { console.error(“Invalid date value”); } else { const isoDueDate = taskDueDate.toISOString(); 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}, }, }); if (response.data) { console.log(“Google Tasks Response:”, response.data); const tasksArray = response.data.items; const notionTaskTitle = steps.trigger.event.properties.Task.title[0].plain_text; const existingTask = tasksArray.find(task => task.title === notionTaskTitle); if (existingTask) { // Update the existing task const taskId = existingTask.id; const notionTaskCompleted = steps.trigger.event.properties.done.checkbox; const googleTaskStatus = notionTaskCompleted ? “completed” : “needsAction”; try { const response = await axios(this, { method: “PUT”, 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: { status: googleTaskStatus, due: isoDueDate, notes: this.notion_page_url, }, }); console.log(“Task updated:”, response.data);
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 Notion trigger named “Updated Page in Database” that emits an event when a page in my Notion database is updated. A Google Tasks action named “list_tasks” retrieves the tasks from your Google Tasks list. 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’m running this code from chat GPT, but it doesn’t seem to be updating because it’s not finding the matching task in google tasks or perhaps another reason. Here’s the code
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”,
},
notion_due_date: {
type: “string”,
label: “Notion Due Date”,
},
notion_page_url: {
type: “string”,
label: “Notes”,
},
},
async run({ steps, $ }) {
try {
console.log(“Starting the component…”);
**const** taskDueDate = **new** Date(**this**.notion_due_date);
**if** (isNaN(taskDueDate.getTime())) {
console.error("Invalid date value");
} **else** {
**const** isoDueDate = taskDueDate.toISOString();
_// 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);
**if** (tasksArray && tasksArray.length > 0) {
**const** updateTasksPromises = tasksArray.map(**async** (task) => {
console.log("Task:", task);
**const** taskId = task.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);
}
});
**await** Promise.all(updateTasksPromises);
}
} **else** {
console.log("Google Tasks Response is empty. Creating a new task...");
}
}
console.log("Completed the component successfully.");
} **catch** (error) {
console.error("Error in the component:", error);
}
},
};
I see that you’re trying to update Google Tasks based on updates in your Notion database. I noticed that the code you provided is updating the tasks in Google Tasks, but it’s not creating a new task if it doesn’t exist. To create a new task when it doesn’t exist in Google Tasks, you can add a new action after the existing code for updating tasks. Here’s the updated code: ``` 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”, }, 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…”); const taskDueDate = new Date(this.notion_due_date); if (isNaN(taskDueDate.getTime())) { console.error(“Invalid date value”); } else { const isoDueDate = taskDueDate.toISOString(); // 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:”, tasks
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 Notion trigger named “Updated Page in Database” that emits an event when a page in your Notion database is updated. A Google Tasks action named “list_tasks” retrieves the tasks from your Google Tasks list. 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. However, it doesn’t seem to be updating in google tasks. This is the code: 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”,
},
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…”);
**const** taskDueDate = **new** Date(**this**.notion_due_date);
**if** (isNaN(taskDueDate.getTime())) {
console.error("Invalid date value");
} **else** {
**const** isoDueDate = taskDueDate.toISOString();
_// 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** matchingTask = tasksArray.find((task) => {
**const** taskTitle = task.title || "";
**return** taskTitle.startsWith(**this**.notion_task_title.substring(0, 7));
});
**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. No action taken.");
}
} **else** {
console.log("Google Tasks Response is empty.");
}
}
console.log("Completed the component successfully.");
} **catch** (error) {
console.error("Error in the component:", error);
}
},
};
And here are the logs when I test the workflow with a new task: 9/16/2023, 9:11:49 AM
Starting the component...
9/16/2023, 9:11:49 AM
HTTP Request to Google Tasks API: {
method: 'GET',
url: 'https://tasks.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks',
headers: {
Authorization: 'Bearer ya29.a0AfB_byAiShQ2Snj_U1453bOOdcMCuNWf5-_C4WyN3frODrULc0_Gu5GuEpDQa7io6rv6Gac79LQ1S5aJbYmkuhkFU_y53mvaDYJP2A07aaob7bnRX6HQ5ZUlukl-XpsTMERrBrEwgApUu2FSUH9guuyNNd_qPoC2FhwqMAaCgYKAY4SARMSFQGOcNnCqiHYPZGJIx4zja0uwEoP0Q0173'
}
}
9/16/2023, 9:11:49 AM
Google Tasks Response is empty.
9/16/2023, 9:11:49 AM
Completed the component successfully.
I see that you’re trying to update Google Tasks based on changes in your Notion tasks. From the logs you provided, it seems that the Google Tasks response is empty. This might be caused by an issue with the task list ID or the API request. First, please double-check if the task_list_id you provided is correct. You can find the correct task list ID by using the Google Tasks API or by checking it in the Google Tasks app. If the task list ID is correct, let’s try adding some error handling to the initial API request to get more information on why the response is empty. Update the axios request in the run method like this: ```
try { 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}, }, }); // Rest of the code } catch (error) { console.error(“Error fetching tasks from Google Tasks API:”, error.response ? error.response.data : error); }
Can you merge that error handing into the API request into my code?
Of course! I’ll merge the error handling into your existing code. Please provide the code you’re currently using, so I can add the error handling to it.
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”,
},
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…”);
const taskDueDate = new Date(this.notion_due_date);
if (isNaN(taskDueDate.getTime())) {
console.error("Invalid date value");
} else {
const isoDueDate = taskDueDate.toISOString();
// 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 matchingTask = tasksArray.find((task) => {
const taskTitle = task.title || "";
return taskTitle.startsWith(this.notion_task_title.substring(0, 7));
});
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. No action taken.");
}
} else {
console.log("Google Tasks Response is empty.");
}
}
console.log("Completed the component successfully.");
} catch (error) {
console.error("Error in the component:", error);
}
},
};
I’ve added error handling to your existing code. Here’s the updated version: ``` 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”, }, 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…”); const taskDueDate = new Date(this.notion_due_date); if (isNaN(taskDueDate.getTime())) { console.error(“Invalid date value”); return; } const isoDueDate = taskDueDate.toISOString(); 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}, }, }).catch((error) => { console.error(“Error fetching tasks:”, error.response ? error.response.data : error); throw error; }); if (response && response.data) { console.log(“Google Tasks Response:”, response.data); const tasksArray = response.data.items; const matchingTask = tasksArray.find((task) => { const taskTitle = task.title || “”; return taskTitle.startsWith(this.notion_task_title.substring(0, 7)); }); if (matchingTask) { const taskId = matchingTask.id; const notionTaskCompleted = steps.trigger.event.properties.done.checkbox; const googleTaskStatus = notionTaskCompleted ? “completed” : “needsAction”; 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},