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

In this code, the prop used to check if tasks match in Google Tasks and the Notion database is notionUrl. The line const matchingTask = tasks.find(task => task.notes.includes(notionPageUrl)); searches for a task in Google Tasks that has a notes field containing the notionPageUrl.

I would like to create another step in my workflow that updates the due date of a task in google tasks when the trigger sees an updated due date.

To create another step in your workflow that updates the due date of a task in Google Tasks when the trigger sees an updated due date, you can use the “Update Task” action from the Google Tasks app. Here’s how to add it to your workflow: 1. After your existing steps, add a new step and search for the “Google Tasks” app. 2. Select the “Update Task” action. 3. Connect your Google Tasks account. 4. Select a Task List or pass a string from a previous step. 5. Select a Task or pass a string from a previous step. 6. Leave the “Title” field empty, as we don’t want to update the title. 7. Set the “Due” field to the updated due date from the trigger or a previous step. Once you’ve configured the “Update Task” action, it will update the due date of the specified task when the trigger sees an updated due date.

I would like for that step to work for more than one task at a time.

To update the due dates of multiple tasks at once, you can modify the existing code to loop through an array of tasks and update their due dates. Here’s an example of how you can achieve this: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google_tasks: { type: "app", app: "google_tasks", }, tasksToUpdate: { type: "string[]", label: "Tasks to Update", description: "Enter the task IDs and their new due dates in JSON format, e.g. [{\"id\": \"task1\", \"dueDate\": \"2023-01-01\"}, {\"id\": \"task2\", \"dueDate\": \"2023-02-01\"}]", }, }, async run({ steps }) { const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; for (const taskToUpdate of this.tasksToUpdate) { const taskInfo = JSON.parse(taskToUpdate); const taskId = taskInfo.id; const newDueDate = taskInfo.dueDate; 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, }); } } }, }); In this code, the tasksToUpdate prop accepts an array of JSON strings, each containing a task ID and its new due date. The component then loops through the array, finds the corresponding task in Google Tasks, and updates its due date.

How should I create the JSON array?

To create a JSON array for updating multiple tasks, you can follow this format: on [ { "id": "task1", "dueDate": "2023-01-01" }, { "id": "task2", "dueDate": "2023-02-01" } ] Each object in the array represents a task with its id and the new dueDate. You can add more task objects to the array as needed. Make sure to replace the id and dueDate values with the actual task IDs and updated due dates you want to use.

Is there are different way to write this code to use the previous steps in the workflow, maybe from the trigger that checks for updated dtabase entrys?

Yes, you can use the data from the previous steps in the workflow to update the due dates of multiple tasks. Assuming you have a trigger that checks for updated database entries and provides an array of tasks with their new due dates, you can modify the code like this: 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; // Replace 'trigger' with the actual name of your trigger step const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; for (const taskToUpdate of updatedTasks) { const taskId = taskToUpdate.id; const newDueDate = taskToUpdate.dueDate; 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, }); } } }, }); In this code, steps.trigger.event.updatedTasks should be replaced with the actual data from your trigger step that contains the updated tasks with their new due dates. The rest of the code remains the same, looping through the updated tasks and updating their due dates in Google Tasks.

When I used that code, I got this error: TypeError
updatedTasks is not iterable
DETAILS

    at Object.run (file:///tmp/__pdg__/dist/code/d143b0afdc10af8272e5c1608b4da095e9ea890870ad03eb922c0aa29110d66d/component.mjs:15:32)
    at null.executeComponent (/var/task/launch_worker.js:229:53)
    at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)

I apologize for the issue you encountered. It seems that the updatedTasks variable might not be an array or is undefined. To fix this, let’s add a check to ensure that updatedTasks is an array before iterating over it. Update the code like this: 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; // Replace 'trigger' with the actual name of your trigger step const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; if (Array.isArray(updatedTasks)) { for (const taskToUpdate of updatedTasks) { const taskId = taskToUpdate.id; const newDueDate = taskToUpdate.dueDate; 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, }); } } } else { console.log("updatedTasks is not an array or is undefined."); } }, }); This code checks if updatedTasks is an array before iterating over it. If it’s not an array, it logs a message to the console. Make sure to replace the ‘trigger’ with the actual name of your trigger step that provides the updated tasks data.

The log says this: updatedTasks is not an array or is undefined.

I apologize for the confusion. It seems that the data from the trigger step is not in the expected format. To better understand the issue, let’s log the data from the trigger step and see its structure. Please update the code like this: ```
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; console.log(“Data from trigger step:”, steps.trigger.event); const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; if (Array.isArray(updatedTasks)) { for (const taskToUpdate of updatedTasks) { const taskId = taskToUpdate.id; const newDueDate = taskToUpdate.dueDate; 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, }); } } } else { console.log(“updatedTasks is not an array or is undefined.”); } }, });

Here’s what that log has:
Data from trigger step: {
archived: false,
cover: null,
created_by: { id: ‘3cedf2c3-e21c-4e03-8425-14f2e482d074’, object: ‘user’ },
created_time: ‘2023-09-19T14:30:00.000Z’,
icon: {
external: { url: ‘https://www.notion.so/icons/square_blue.svg’ },
type: ‘external’
},
id: ‘8ebe208e-f678-4205-a052-bd3c426a4d9a’,
last_edited_by: { id: ‘3cedf2c3-e21c-4e03-8425-14f2e482d074’, object: ‘user’ },
last_edited_time: ‘2023-09-19T14:30:00.000Z’,
object: ‘page’,
parent: {
database_id: ‘1165ab1d-5fdb-4a88-b6bc-c45ae0d2d9d7’,
type: ‘database_id’
},
properties: {
‘’: { formula: [Object], id: ‘Bcwx’, type: ‘formula’ },
‘AI custom autofill’: { id: ‘nmQc’, rich_text: [], type: ‘rich_text’ },
Assignee: { id: ‘qbq%3A’, people: [], type: ‘people’ },
Attachments: { files: [], id: ‘Eg%60m’, type: ‘files’ },
Cold: { formula: [Object], id: ‘P%5DbX’, type: ‘formula’ },
Contexts: { id: ‘RSzs’, multi_select: [], type: ‘multi_select’ },
Created: {
created_time: ‘2023-09-19T14:30:00.000Z’,
id: ‘A%7BvH’,
type: ‘created_time’
},
‘Created By’: { created_by: [Object], id: ‘FH%3DW’, type: ‘created_by’ },
‘Created Stamp (Parent)’: { formula: [Object], id: ‘nCll’, type: ‘formula’ },
‘Date Received’: { date: null, id: ‘jT%7Dk’, type: ‘date’ },
‘Days (Only if Set to 1 Day(s))’: { id: ‘ZhZF’, multi_select: [], type: ‘multi_select’ },
Divider: { formula: [Object], id: ‘%60sQo’, type: ‘formula’ },
Due: { date: [Object], id: ‘bl%3D%3B’, type: ‘date’ },
‘Due Stamp (Parent)‘: { formula: [Object], id: ‘%7BP%5BX’, type: ‘formula’ },
‘Due Timestamp’: { formula: [Object], id: ‘qHs%3F’, type: ‘formula’ },
Edited: {
id: ‘%3A%60BZ’,
last_edited_time: ‘2023-09-19T14:30:00.000Z’,
type: ‘last_edited_time’
},
‘Edited Stamp (Parent)’: { formula: [Object], id: ‘mg%3BS’, type: ‘formula’ },
‘Email Image’: { files: [], id: ‘kv_w’, type: ‘files’ },
‘First Weekday Base Date’: { formula: [Object], id: ‘RX~z’, type: ‘formula’ },
Formula: { formula: [Object], id: ‘%3F%5B%7C%7C’, type: ‘formula’ },
From: { email: null, id: ‘kkU%3B’, type: ‘email’ },
‘Google Event ID’: { id: ‘y%3Bn_‘, rich_text: [], type: ‘rich_text’ },
‘Kanban - Tag’: { id: ‘H~vq’, select: null, type: ‘select’ },
‘Kanban Status’: { id: ‘xkX~’, select: [Object], type: ‘select’ },
‘Last Day Base Date’: { formula: [Object], id: ‘peb%5D’, type: ‘formula’ },
‘Last Weekday Base Date’: { formula: [Object], id: ‘%3DLRE’, type: ‘formula’ },
Late: { formula: [Object], id: ‘aG%7CO’, type: ‘formula’ },
‘Next Due’: { formula: [Object], id: ‘WcB%5C’, type: ‘formula’ },
‘Next Last Base Date’: { formula: [Object], id: ‘BSU%7D’, type: ‘formula’ },
Note: { id: ‘%7Dfh~’, rich_text: [], type: ‘rich_text’ },
‘Parent Created’: { id: ‘%3B%40Rc’, rollup: [Object], type: ‘rollup’ },
‘Parent Due Timestamp’: { id: ‘Ct%3DV’, rollup: [Object], type: ‘rollup’ },
‘Parent Edited’: { id: ‘z%3BDP’, rollup: [Object], type: ‘rollup’ },
‘Parent Project’: { id: ‘ONGc’, rollup: [Object], type: ‘rollup’ },
‘Parent Smart List’: { id: ‘Q%5DRX’, rollup: [Object], type: ‘rollup’ },
‘Parent Snooze’: { id: ‘%3Edy%7D’, rollup: [Object], type: ‘rollup’ },
‘Parent Task’: { has_more: false, id: ‘uyrv’, relation: [], type: ‘relation’ },
‘Parent Wait’: { id: ‘lA%7DG’, rollup: [Object], type: ‘rollup’ },
Preview: { files: [], id: ‘FMfT’, type: ‘files’ },
Priority: { id: ‘%3E%3DOL’, select: [Object], type: ‘select’ },
‘Priority Project’: { id: ‘Ges%3D’, rollup: [Object], type: ‘rollup’ },
Project: { has_more: false, id: ‘a~%7Cl’, relation: [], type: ‘relation’ },
‘Project Area’: { id: ‘p%5Dy%5D’, rollup: [Object], type: ‘rollup’ },
‘Quick Capture Box’: { formula: [Object], id: ‘Wlps’, type: ‘formula’ },
‘Recur Interval’: { id: ‘mvpx’, number: null, type: ‘number’ },
‘Recur Unit’: { id: ‘a%5ESo’, select: null, type: ‘select’ },
‘Simplified Recur Unit’: { formula: [Object], id: ‘aO_%5C’, type: ‘formula’ },
‘Smart List’: { id: ‘x%5BU%60’, select: null, type: ‘select’ },
‘Smart List (Formula)‘: { formula: [Object], id: ‘%40w%3BB’, type: ‘formula’ },
Snooze: { date: null, id: ‘WU%3AS’, type: ‘date’ },
‘Snooze (Parent)’: { formula: [Object], id: ‘t_%40~’, type: ‘formula’ },
Start: { date: null, id: ‘nkuw’, type: ‘date’ },
‘Sub Seed’: { formula: [Object], id: ‘%5B%7BZP’, type: ‘formula’ },
‘Sub Seed Name’: { formula: [Object], id: ‘%7BZyV’, type: ‘formula’ },
‘Sub-Task Count’: { id: ‘ptv%40’, rollup: [Object], type: ‘rollup’ },
‘Sub-Tasks’: { has_more: false, id: ‘wzvD’, relation: [], type: ‘relation’ },
Task: { id: ‘title’, title: [Array], type: ‘title’ },
To: { id: ‘%7B%7B%3C%60’, rich_text: [], type: ‘rich_text’ },
Type: { formula: [Object], id: ‘anYj’, type: ‘formula’ },
URL: { id: ‘LCOu’, type: ‘url’, url: null },
‘UTC Offset’: { formula: [Object], id: ‘z%3AMU’, type: ‘formula’ },
‘Wait (Parent)’: { formula: [Object], id: ‘E%3CEr’, type: ‘formula’ },
‘Wait Date’: { date: null, id: ‘HqS_‘, type: ‘date’ },
done: { checkbox: false, id: ‘_D%5ER’, type: ‘checkbox’ },
‘google task date format’: { formula: [Object], id: ‘PyKz’, type: ‘formula’ },
:stopwatch: Recurring Divider’: { formula: [Object], id: ‘%5CN%5BS’, type: ‘formula’ },
:white_check_mark: Sub-Task Divider’: { formula: [Object], id: ‘k%5B%7Cq’, type: ‘formula’ }
},
public_url: ‘https://mcmahen.notion.site/Trying-code-to-see-if-it-ll-create-a-new-task-8ebe208ef6784205a052bd3c426a4d9a’,
url: ‘https://www.notion.so/Trying-code-to-see-if-it-ll-create-a-new-task-8ebe208ef6784205a052bd3c426a4d9a’
}

It looks like you have a log containing data from a Notion trigger step. If you want to use this data in a Pipedream workflow, you can access the properties of the steps.trigger.event object. For example, if you want to get the created_time property, you can use steps.trigger.event.created_time. Here’s an example of a Pipedream component that returns the created_time property from the trigger data: export default defineComponent({ async run({ steps }) { const createdTime = steps.trigger.event.created_time; return createdTime; }, }); You can replace created_time with any other property you want to access from the trigger data.

So, in this use case where I’m trying to update due dates, what would code look like in a google tasks step? I would like the “google task date format” property to sync to the due date in google tasks and update the google task of a matching task.

To update the due date of a Google Task, you’ll need to make a request to the Google Tasks API. Here’s an example Pipedream component that updates the due date of a task: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google: { type: "app", app: "google", }, taskId: { type: "string", label: "Task ID", }, taskListId: { type: "string", label: "Task List ID", }, dueDate: { type: "string", label: "Due Date", }, }, async run({ steps, $ }) { const apiUrl = `https://www.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks/${this.taskId}`; const updatedTask = await axios($, { method: "PATCH", url: apiUrl, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, data: { due: this.dueDate, }, }); return updatedTask; }, }); Replace the taskId, taskListId, and dueDate props with the appropriate values. The dueDate should be in the format “YYYY-MM-DDTHH:MM:SSZ”. This component will update the due date of the specified task in the specified task list.

I don’t think I was clear. I want to update the following code to work for the property of the trigger step called: steps.trigger.event.properties[“google task date format”].formula.string

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; // Replace 'trigger' with the actual name of your trigger step
    const tasksData = steps.list_tasks.data;
    const tasks = tasksData && tasksData.tasks ? tasksData.tasks : [];

    for (const taskToUpdate of updatedTasks) {
      const taskId = taskToUpdate.id;
      const newDueDate = taskToUpdate.dueDate;

      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,
        });
      }
    }
  },
});

I understand now. You want to update the due date of a Google Task using the value from steps.trigger.event.properties["google task date format"].formula.string. Here’s the modified 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, }); } } }, }); This code will now use the value from steps.trigger.event.properties["google task date format"].formula.string as the new due date when updating the Google Task.

Will this code work if multiple tasks are all updated when the action is triggered?