How to Modify Code to Filter the Correct Google Task List in a Notion Database Update Workflow?

I apologize for the confusion earlier. Based on the response you provided, it seems that the task doesn’t have a notes property, which is why the filter isn’t finding any items. To handle this, we can modify the filter condition to check for the existence of the notes property before checking its length. Here’s the updated code: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, taskListId: { type: “string”, label: “Task List ID”, default: “Mk1hZng3dVdLeEJ6ZVZqUg”, }, }, async run({ steps, $ }) { const response = await axios($, { url: https://www.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, }, }); console.log(“Response:”, response); if (response.data && response.data.items) { console.log(“Tasks before filtering:”, response.data.items); const existingTasks = response.data.items.filter(task => task.notes && task.notes.length > 0); return existingTasks; } else { console.log(“No items found in the response. Response data:”, response.data); } }, });

Actually, I think I only need to check for the existence. If the notes property is there it doesn’t matter how long it is. Can you adjust the code for that?

Certainly! Here’s the updated code that checks for the existence of the notes property, regardless of its length: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, taskListId: { type: “string”, label: “Task List ID”, default: “Mk1hZng3dVdLeEJ6ZVZqUg”, }, }, async run({ steps, $ }) { const response = await axios($, { url: https://www.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, }, }); console.log(“Response:”, response); if (response.data && response.data.items) { console.log(“Tasks before filtering:”, response.data.items); const existingTasks = response.data.items.filter(task => task.notes); return existingTasks; } else { console.log(“No items found in the response. Response data:”, response.data); } }, });

What does this part of the code do?
if (existingTasks && existingTasks.length > 0) {
// Update the existing task’s due date
const taskId = existingTasks[0].id;
const taskListId = existingTasks[0].taskListId;

This part of the code checks if there are any existing tasks (with the notes property) in the existingTasks array and if the array is not empty. If the condition is met, it means there are tasks with the notes property. Then, it extracts the id and taskListId of the first task in the existingTasks array. These values can be used later to update the task’s due date or perform other operations on the task.

I would like for this code to only create a new task if there’s not already a task with notes in google tasks. I want to wait for a separate step to update the due dates or the completion status. Here’s what code I have now that I’d like to modify:

import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    google_tasks: {
      type: "app",
      app: "google_tasks",
    },
    title: {
      type: "string",
      label: "Notion Page Title",
    },
    notionUrl: {
      type: "string",
      label: "Notion Page URL",
    },
    dueDate: {
      type: "string",
      label: "Due Date",
    },
    taskListId: {
      type: "string",
      label: "Task List ID",
      default: "Mk1hZng3dVdLeEJ6ZVZqUg",
    },
  },
  async run({ steps }) {
    const existingTasks = steps.google_tasks_notes_filter.filteredTasks;
    const title = this.title;
    const dueDate = this.dueDate;

    if (existingTasks && existingTasks.length > 0) {
      // Update the existing task's due date
      const taskId = existingTasks[0].id;
      const taskListId = existingTasks[0].taskListId;

      await axios(this, {
        method: "POST",
        url: `https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks/${taskId}`,
        headers: {
          Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`,
          "Content-Type": "application/json",
        },
        data: {
          due: dueDate,
        },
      });
    } else {
      // Create a new task
      const url = `https://www.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks`;
      const body = {
        title: title,
        due: dueDate,
        notes: this.notionUrl,
      };

      await axios(this, {
        method: "POST",
        url: url,
        headers: {
          Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`,
          "Content-Type": "application/json",
        },
        data: body,
      });
    }
  },
}); 

To modify the code so that it only creates a new task if there’s not already a task with notes in Google Tasks, you can remove the part that updates the existing task’s due date. Here’s the updated code: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, title: { type: “string”, label: “Notion Page Title”, }, notionUrl: { type: “string”, label: “Notion Page URL”, }, dueDate: { type: “string”, label: “Due Date”, }, taskListId: { type: “string”, label: “Task List ID”, default: “Mk1hZng3dVdLeEJ6ZVZqUg”, }, }, async run({ steps }) { const existingTasks = steps.google_tasks_notes_filter.filteredTasks; if (existingTasks && existingTasks.length > 0) { // Do nothing, wait for a separate step to update the due dates or the completion status } else { // Create a new task const url = https://www.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks; const body = { title: this.title, due: this.dueDate, notes: this.notionUrl, }; await axios(this, { method: “POST”, url: url, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: body, }); } }, });

I’m trying to create a workflow that will sync my tasks from a notion database to my google tasks, with the focus being on when I mark a task complete in notion, that it will mark that matching task in google tasks. What step should I use?

To create a workflow that syncs tasks from a Notion database to Google Tasks and marks tasks as complete in Google Tasks when marked complete in Notion, you can use the following steps: 1. Use the Notion — Updated Page in Database trigger to detect when a task is updated in your Notion database. You can find this trigger by searching for the Notion app in the trigger menu. Connect your Notion account and select the appropriate database. 2. Add a Code step to check if the task is marked as complete in Notion. You can access the updated task data using steps.trigger.event. If the task is marked as complete, proceed to the next step. 3. Use the Google Tasks — Query Tasks action to search for the matching task in Google Tasks. You can find this action by searching for the Google Tasks app in the step menu. Connect your Google Tasks account and provide the necessary parameters, such as the task list ID and a filter to find the matching task based on the task title or other unique identifiers. 4. Add another Code step to check if the matching task is found in Google Tasks. If found, extract the task ID and proceed to the next step. 5. Use the Google Tasks — Update Task action to mark the matching task as complete in Google Tasks. Provide the task list ID, task ID, and set the status parameter to “completed”. Here’s a high-level outline of the workflow: 1. Notion — Updated Page in Database (trigger) 2. Code step (check if task is marked as complete in Notion) 3. Google Tasks — Query Tasks (find matching task in Google Tasks) 4. Code step (check if matching task is found and extract task ID) 5. Google Tasks — Update Task (mark task as complete in Google Tasks)

What would this step look like? Add a Code step to check if the task is marked as complete in Notion. You can access the updated task data using steps.trigger.event. If the task is marked as complete, proceed to the next step. This is the path for the done checkbox: steps.trigger.event.properties.done.checkbox

Here’s a Code step to check if the task is marked as complete in Notion using the provided path for the “done” checkbox: export default defineComponent({ async run({ steps }) { const isTaskComplete = steps.trigger.event.properties.done.checkbox; if (isTaskComplete) { // Task is marked as complete in Notion, proceed to the next step return { taskComplete: true }; } else { // Task is not marked as complete, you can exit the workflow or handle this case as needed return { taskComplete: false }; } }, }); This code checks the “done” checkbox value from the Notion trigger event and returns an object with a taskComplete property, which indicates whether the task is complete or not. You can use this value in the next steps of your workflow to conditionally execute actions based on the task’s completion status.

I can’t find this the Google Tasks — Query Tasks action to search for the matching task in Google Tasks. It’s not one of the options. I only have list tasks, create task list, delete task, update task, create task, list task lists, delete task list, and update task list.

Apologies for the confusion earlier. Since there isn’t a specific “Query Tasks” action available for Google Tasks, you can use the Google Tasks — List Tasks action instead to fetch tasks from a specific task list. Here’s how you can proceed: 1. Add the Google Tasks — List Tasks action to your workflow. 2. Connect your Google Tasks account. 3. Provide the necessary parameters, such as the task list ID. 4. Add a Code step after the List Tasks action to filter and find the matching task based on the task title or other unique identifiers. Here’s an example of the filtering code: ```
const notionTaskTitle = “Your Notion Task Title”; // Replace this with the actual title or variable const tasks = steps.list_tasks.$return_value.items; const matchingTask = tasks.find(task => task.title === notionTaskTitle); if (matchingTask) { // Matching task found, extract the task ID and proceed to the next step return { taskId: matchingTask.id, taskFound: true }; } else { // Task not found, handle this case as needed return { taskFound: false }; }

If I built a code step after that list tasks action, but I wanted the filtering code matching to be based on this path (steps.trigger.event.public_url) being in the notes prop of the Google code.

To filter the tasks based on the steps.trigger.event.public_url being in the notes property of the Google Tasks, you can modify the filtering code in the Code step like this: const notionPublicUrl = steps.trigger.event.public_url; const tasks = steps.list_tasks.$return_value.items; const matchingTask = tasks.find(task => task.notes && task.notes.includes(notionPublicUrl)); if (matchingTask) { // Matching task found, extract the task ID and proceed to the next step return { taskId: matchingTask.id, taskFound: true }; } else { // Task not found, handle this case as needed return { taskFound: false }; } This code checks if the notionPublicUrl is present in the notes property of each task in the Google Tasks list. If a matching task is found, it returns the task ID and a taskFound flag set to true. If no matching task is found, it returns a taskFound flag set to false.

I got this error when using that code: Code Error
‘return’ outside of function. (9:2)

I apologize for the mistake in the code I provided earlier. Here’s the corrected Code step to filter the tasks based on the steps.trigger.event.public_url being in the notes property of the Google Tasks: export default defineComponent({ async run({ steps }) { const notionPublicUrl = steps.trigger.event.public_url; const tasks = steps.list_tasks.$return_value.items; const matchingTask = tasks.find(task => task.notes && task.notes.includes(notionPublicUrl)); if (matchingTask) { // Matching task found, extract the task ID and proceed to the next step return { taskId: matchingTask.id, taskFound: true }; } else { // Task not found, handle this case as needed return { taskFound: false }; } }, }); This code should now work correctly within the run method of the Pipedream component.

This code
export default defineComponent({
async run({ steps }) {
const notionPublicUrl = steps.trigger.event.public_url;
const tasks = steps.list_tasks.$return_value.items;

**const** matchingTask = tasks.find(task => task.notes && task.notes.includes(notionPublicUrl));

**if** (matchingTask) {
  _// Matching task found, extract the task ID and proceed to the next step_
  **return** { taskId: matchingTask.id, taskFound: **true** };
} **else** {
  _// Task not found, handle this case as needed_
  **return** { taskFound: **false** };
}

},
});
is giving me this error now: TypeError
Cannot read properties of undefined (reading ‘find’)
What’s going on?

I apologize for the confusion. It seems there might be an issue with the tasks variable or the data returned by the steps.list_tasks.$return_value.items. To debug this issue, let’s add a console.log statement to inspect the tasks variable before the find operation: export default defineComponent({ async run({ steps }) { const notionPublicUrl = steps.trigger.event.public_url; const tasks = steps.list_tasks.$return_value.items; console.log('Tasks:', tasks); // Add this line to inspect the tasks variable const matchingTask = tasks.find(task => task.notes && task.notes.includes(notionPublicUrl)); if (matchingTask) { return { taskId: matchingTask.id, taskFound: true }; } else { return { taskFound: false }; } }, }); After adding the console.log statement, run the workflow again and check the logs to see the output of the tasks variable. This should help identify if there’s an issue with the data returned by the steps.list_tasks.$return_value.items. If the issue persists, please let me know the output of the console.log statement, and I’ll help you further.

The log was Tasks: undefined