What are the Elements of a Workflow in <http://Pipedream.com|Pipedream.com> that Update Google Tasks Lists from Notion Updates?

Yes, the code you provided will work for multiple tasks when the action is triggered. It iterates through the updatedTasks array and updates each task’s due date using the value from steps.trigger.event.properties["google task date format"].formula.string. If multiple tasks are present in the updatedTasks array, the code will update the due date for each of them.

I’m getting this error: updatedTasks is not iterable. What do I need to change to make that iterable or is there a different title I need to reference for “updated tasks”?

I apologize for the confusion. It seems there might be an issue with the updatedTasks variable. To ensure that updatedTasks is an iterable array, you can update the code like this: const updatedTasks = steps.trigger.event.updatedTasks || []; This will set updatedTasks to an empty array if it’s not already an array, making it iterable. Here’s the updated code: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, }, async run({ steps }) { const updatedTasks = steps.trigger.event.updatedTasks || []; const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; for (const taskToUpdate of updatedTasks) { const taskId = taskToUpdate.id; const newDueDate = steps.trigger.event.properties[“google task date format”].formula.string; const task = tasks.find((task) => task.id === taskId); if (task) { const url = https://www.googleapis.com/tasks/v1/lists/@default/tasks/${taskId}; const body = { due: newDueDate, }; await axios(this, { method: “PUT”, url: url, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: body, }); } } }, });

What property is this code using to check if the tasks match in notion and google tasks?

The code is using the id property to check if the tasks match in Notion and Google Tasks. In the following line of code, it searches for a task in the tasks array with the same id as the taskId of the task to update: const task = tasks.find((task) => task.id === taskId); If a task with the same id is found, it proceeds to update the due date of the Google Task.

instead of using the task id, could we use the notion url that is in to the notes prop of google tasks (from a previous step)?

Yes, you can use the Notion URL in the notes property of Google Tasks to match tasks instead of using the task ID. Here’s the updated code: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, }, async run({ steps }) { const updatedTasks = steps.trigger.event.updatedTasks || []; const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; for (const taskToUpdate of updatedTasks) { const notionUrl = taskToUpdate.notes; const task = tasks.find((task) => task.notes === notionUrl); if (task) { const taskId = task.id; const newDueDate = steps.trigger.event.properties[“google task date format”].formula.string; const url = https://www.googleapis.com/tasks/v1/lists/@default/tasks/${taskId}; const body = { due: newDueDate, }; await axios(this, { method: “PUT”, url: url, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: body, }); } } }, });

That seems to be working. I want to add a step to my workflow now that syncs the completion step when a task in notion as marked as complete, so that it will mark as complete in Google Tasks as well. The path in the notion trigger is: steps.trigger.event.properties.done.checkbox The type is a checkbox.

I’m glad the previous code is working for you! To sync the completion status between Notion and Google Tasks, you can update the code to check the done property and update the Google Task accordingly. Here’s the updated code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google_tasks: { type: "app", app: "google_tasks", }, }, async run({ steps }) { const updatedTasks = steps.trigger.event.updatedTasks || []; const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; for (const taskToUpdate of updatedTasks) { const notionUrl = taskToUpdate.notes; const task = tasks.find((task) => task.notes === notionUrl); if (task) { const taskId = task.id; const newDueDate = steps.trigger.event.properties["google task date format"].formula.string; const isCompleted = steps.trigger.event.properties.done.checkbox; const url = `https://www.googleapis.com/tasks/v1/lists/@default/tasks/${taskId}`; const body = { due: newDueDate, status: isCompleted ? "completed" : "needsAction", }; await axios(this, { method: "PUT", url: url, headers: { Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: body, }); } } }, }); This code now checks the done property from the Notion trigger (steps.trigger.event.properties.done.checkbox) and updates the Google Task’s status to “completed” if the Notion task is marked as complete, or “needsAction” if it’s not.

I appreciate that, but I’d rather add the completion status sync as a separate step completely to try to keep the code a bit cleaner for troubleshooting. Could you give me a code for just syncing the completion status?

Sure, here’s a separate Pipedream component that syncs the completion status between Notion and Google Tasks: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, }, async run({ steps }) { const updatedTasks = steps.trigger.event.updatedTasks || []; const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; for (const taskToUpdate of updatedTasks) { const notionUrl = taskToUpdate.notes; const task = tasks.find((task) => task.notes === notionUrl); if (task) { const taskId = task.id; const isCompleted = steps.trigger.event.properties.done.checkbox; const url = https://www.googleapis.com/tasks/v1/lists/@default/tasks/${taskId}; const body = { status: isCompleted ? “completed” : “needsAction”, }; await axios(this, { method: “PUT”, url: url, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: body, }); } } }, });

Can you explain the different elements of the code to me?

Certainly! Let’s break down the code into its main elements: 1. Import statement: import { axios } from "@pipedream/platform"; - This imports the axios function from the Pipedream platform package, which is used for making HTTP requests. 2. Component definition: export default defineComponent({ ... }); - This is the main structure of a Pipedream component. It’s a function that takes an object as its single argument. 3. Props: props: { google_tasks: { type: "app", app: "google_tasks", }, }, This part defines the properties that the component accepts as input. In this case, it’s a single property google_tasks, which is an app connection to Google Tasks. 4. Run method: async run({ steps }) { ... } - This is the main function that gets executed when the component runs. It’s an asynchronous function that takes an object with a steps property as its argument. 5. Looping through updated tasks: const updatedTasks = steps.trigger.event.updatedTasks || []; const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; for (const taskToUpdate of updatedTasks) { ... } This part initializes the arrays for updated tasks and existing tasks, and then loops through each updated task. 6. Finding the corresponding task in Google Tasks: const notionUrl = taskToUpdate.notes; const task = tasks.find((task) => task.notes === notionUrl); This part finds the corresponding task in Google Tasks by matching the notes property containing the Notion URL. 7. Updating the Google Task’s completion status: ```
if (task) { const taskId = task.id; const isCompleted = steps.trigger.event.properties.done.checkbox; const url = https://www.googleapis.com/tasks/v1/lists/@default/tasks/${taskId}; const body = { status: isCompleted ? “completed” : “needsAction”, }; await axios(this, { method: “PUT”, url: url, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: body, }); }

It appears that something in that code isn’t functioning properly for google tasks. It did not sync the completed status of the test task, so it didn’t show up as completed in the google tasks list. I checked the status of the task in the trigger and it was true.

I apologize for the issue you’re facing. Let’s try to debug the problem. First, please make sure that the Notion URL in the notes field of the Google Task is correct. If that’s correct, we can add some logging to the code to help identify the issue. Here’s the updated code with added console logs: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, }, async run({ steps }) { const updatedTasks = steps.trigger.event.updatedTasks || []; const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; console.log(“Updated Tasks:”, updatedTasks); console.log(“Google Tasks:”, tasks); for (const taskToUpdate of updatedTasks) { const notionUrl = taskToUpdate.notes; const task = tasks.find((task) => task.notes === notionUrl); console.log(“Task to update:”, taskToUpdate); console.log(“Matching Google Task:”, task); if (task) { const taskId = task.id; const isCompleted = steps.trigger.event.properties.done.checkbox; console.log(“Is completed:”, isCompleted); const url = https://www.googleapis.com/tasks/v1/lists/@default/tasks/${taskId}; const body = { status: isCompleted ? “completed” : “needsAction”, }; await axios(this, { method: “PUT”, url: url, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: body, }); } } }, });

The logs weren’t much help - here’s all I got: 9/19/2023, 11:56:09 AM
Updated Tasks: []

9/19/2023, 11:56:09 AM
Google Tasks: []

I apologize for the inconvenience. It seems that the updated tasks and Google tasks arrays are both empty, which indicates that there might be an issue with the data being fetched or the trigger itself. To further investigate the issue, please provide more information about the trigger you’re using and any relevant configurations. This will help me understand the problem better and provide a more accurate solution.

These are the details on the trigger I’ve been using: Name
Updated Page in Database
Description
Emit new event when a page in a database is updated. To select a specific page, use Updated Page ID instead
Version
0.0.6
Source

Thank you for providing the trigger details. Since the logs showed empty arrays for both updated tasks and Google tasks, let’s ensure that the trigger is set up correctly and fetching the data as expected. Please follow these steps to verify the trigger configuration: 1. In your Pipedream workflow, make sure you’ve selected the “Notion — Updated Page in Database” trigger. 2. Connect your Notion account and select the appropriate database. 3. Generate a test event from Notion by updating a page in the selected database. After completing these steps, check the workflow logs to see if the trigger is capturing the updated tasks correctly. If the issue persists, please let me know, and we’ll investigate further.

I followed the steps you outlined, but it still didn’t mark complete and the logs for the that step at least show this: 9/19/2023, 12:03:26 PM
Updated Tasks: []

9/19/2023, 12:03:26 PM
Google Tasks: []