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

This topic was automatically generated from Slack. You can find the original thread here.

I’m using a workflow in pipedream.com that will update my google tasks lists when I update my tasks in notion. It consists of these elements

  1. A Notion trigger named “Updated Page in Database” emits an event when a page in my Notion database is updated. The database ID is 1165ab1d5fdb4a88b6bcc45ae0d2d9d7
  2. A Google Tasks action step named “list_tasks” retrieves the tasks from my Google Tasks list. These are the inputs for that step: Google Tasks Account Google Tasks LiveIntegrity | Task List :spiral_calendar_pad: Reclaim Mk1hZng3dVdLeEJ6ZVZqUg | Max Results 200 | Show Completed true | Show Deleted false
  3. I want to create a step that will use the “list_tasks” step to check if there are any tasks that match the notion page URL in the notes section of the google tasks list . If there isn’t a matching task, this step would create a task with a title that comes from Notion property, a due date that comes from a notion property, and notes that come from a URL property.

To create a workflow that updates your Google Tasks lists when you update tasks in Notion, you can follow these steps: 1. Use the Notion — Updated Page in Database trigger to detect updates in your Notion tasks. You can find this trigger by searching for the Notion app in the trigger menu. Follow the instructions on the trigger configuration screen to set it up. 2. Add the Google — Update Task action to your workflow. Search for the Google app in the step menu and select the Update Task action. Connect your Google account and configure the required fields, such as Tasklist ID and Task ID. You can pass data from the Notion trigger step to the Google action step as needed. Remember to test your workflow to ensure it’s working as expected. If you need more assistance or have any questions, feel free to ask.

To create a step that checks for matching tasks and creates a new task if there’s no match, you can add a custom code step after the “list_tasks” step. Here’s an example of how you can achieve this: ```
export default defineComponent({ async run({ steps }) { const notionPageUrl = “your_notion_page_url”; // Replace with the Notion page URL from the trigger const tasks = steps.list_tasks.data.tasks; const matchingTask = tasks.find(task => task.notes === notionPageUrl); if (!matchingTask) { // Create a new task using the Notion properties const title = “your_notion_property_title”; // Replace with the title from the Notion property const dueDate = “your_notion_property_due_date”; // Replace with the due date from the Notion property // Use the Google Tasks API to create a new task // Replace “your_google_tasks_list_id” with the list ID from the “list_tasks” step const url = https://www.googleapis.com/tasks/v1/lists/your_google_tasks_list_id/tasks; const body = { title: title, due: dueDate, notes: notionPageUrl }; await axios(this, { method: “POST”, url: url, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}, “Content-Type”: “application/json” }, data: body }); } }, });

When I entered this code: import { axios } from@pipedream/platform”
export default defineComponent({
async run({ steps }) {
const notionPageUrl = “steps.trigger.event.url”;
const tasks = steps.list_tasks.data.tasks;
const matchingTask = tasks.find(task => task.notes === notionPageUrl);

**if** (!matchingTask) {
  _// Create a new task using the Notion properties_
  **const** title = “ysteps.trigger.event.properties.Task.title[0].plain_text”;
  **const** dueDate = “steps.trigger.event.properties[“google task date format”].formula.string”;

  _// Use the Google Tasks API to create a new task_
  _// Replace “your_google_tasks_list_id” with the list ID from the “list_tasks” step_
  **const** url = `https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks`;
  **const** body = {
    title: title,
    due: dueDate,
    notes: notionPageUrl
  };

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

},
});
I got this error:

Code Error
Unexpected token (11:55)
DETAILS

SyntaxError: Unexpected token (11:55)
    at pp$4.raise (/var/task/node_modules/acorn/dist/acorn.js:2927:15)
    at pp.unexpected (/var/task/node_modules/acorn/dist/acorn.js:698:10)
    at pp.semicolon (/var/task/node_modules/acorn/dist/acorn.js:675:66)
    at pp$1.parseVarStatement (/var/task/node_modules/acorn/dist/acorn.js:1102:10)
    at pp$1.parseStatement (/var/task/node_modules/acorn/dist/acorn.js:851:19)
    at anonymous.parseStatement (/var/task/node_modules/acorn-node/lib/dynamic-import/index.js:65:118)
    at anonymous.parseStatement (/var/task/node_modules/acorn-node/lib/import-meta/index.js:45:48)
    at pp$1.parseBlock (/var/task/node_modules/acorn/dist/acorn.js:1170:23)
    at pp$1.parseStatement (/var/task/node_modules/acorn/dist/acorn.js:854:36)
    at anonymous.parseStatement (/var/task/node_modules/acorn-node/lib/dynamic-import/index.js:65:118)

I got this error: Code Error
Unexpected token (11:55)
DETAILS

SyntaxError: Unexpected token (11:55)
    at pp$4.raise (/var/task/node_modules/acorn/dist/acorn.js:2927:15)
    at pp.unexpected (/var/task/node_modules/acorn/dist/acorn.js:698:10)
    at pp.semicolon (/var/task/node_modules/acorn/dist/acorn.js:675:66)
    at pp$1.parseVarStatement (/var/task/node_modules/acorn/dist/acorn.js:1102:10)
    at pp$1.parseStatement (/var/task/node_modules/acorn/dist/acorn.js:851:19)
    at anonymous.parseStatement (/var/task/node_modules/acorn-node/lib/dynamic-import/index.js:65:118)
    at anonymous.parseStatement (/var/task/node_modules/acorn-node/lib/import-meta/index.js:45:48)
    at pp$1.parseBlock (/var/task/node_modules/acorn/dist/acorn.js:1170:23)
    at pp$1.parseStatement (/var/task/node_modules/acorn/dist/acorn.js:854:36)
    at anonymous.parseStatement (/var/task/node_modules/acorn-node/lib/dynamic-import/index.js:65:118)

I noticed that there are some issues with the code you provided, specifically with the use of quotes and backticks. Here’s the corrected version of the code: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ async run({ steps }) { const notionPageUrl = steps.trigger.event.url; const tasks = steps.list_tasks.data.tasks; const matchingTask = tasks.find(task => task.notes === notionPageUrl); if (!matchingTask) { // Create a new task using the Notion properties const title = steps.trigger.event.properties.Task.title[0].plain_text; const dueDate = steps.trigger.event.properties[“google task date format”].formula.string; // Use the Google Tasks API to create a new task const url = https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks; const body = { title: title, due: dueDate, notes: notionPageUrl }; await axios(this, { method: “POST”, url: url, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}, “Content-Type”: “application/json” }, data: body }); } }, });

I see that you’re encountering a syntax error in your code. It seems like the issue is related to the use of incorrect quotes. You should use regular double quotes (") or single quotes (') instead of the stylized quotes you’re using (e.g., and ). Here’s the corrected version of your code: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ async run({ steps }) { const notionPageUrl = steps.trigger.event.url; const tasks = steps.list_tasks.data.tasks; const matchingTask = tasks.find(task => task.notes === notionPageUrl); if (!matchingTask) { const title = steps.trigger.event.properties.Task.title[0].plain_text; const dueDate = steps.trigger.event.properties[“google task date format”].formula.string; const url = https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks; const body = { title: title, due: dueDate, notes: notionPageUrl }; await axios(this, { method: “POST”, url: url, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}, “Content-Type”: “application/json” }, data: body }); } }, });

I tested the code, and it says it was successful, but there’s no exports and the test event didn’t show up in my google tasks list.

I’m sorry to hear that the code didn’t produce the expected results. To help you better, I’ll need some more information about your workflow. Can you please provide the following details? 1. The trigger you’re using for your workflow. 2. The complete code you’re using in the Pipedream component. Once I have this information, I’ll be able to assist you in identifying and resolving the issue.

  1. A Notion trigger named “Updated Page in Database” emits an event when a page in my Notion database is updated. The database ID is 1165ab1d5fdb4a88b6bcc45ae0d2d9d7
  2. A Google Tasks action step named “list_tasks” retrieves the tasks from my Google Tasks list. These are the inputs for that step: Google Tasks Account Google Tasks LiveIntegrity | Task List :spiral_calendar_pad: Reclaim Mk1hZng3dVdLeEJ6ZVZqUg | Max Results 200 | Show Completed true | Show Deleted false
    And here’s the code for the current step that I’m having issues with:

async (event, steps) => {
const notionPageUrl = steps.trigger.event.url; // Access the Notion page URL using steps.trigger.event.url

// Retrieve the tasks from Google Tasks
const tasks = await steps.list_tasks.$return_value;

// Check if any task’s notes contain the Notion page URL
const matchingTask = tasks.find(task => task.notes.includes(notionPageUrl));

// If a matching task is found, you can choose to update it instead of creating a new task
if (matchingTask) {
// Update the existing task with the necessary information
// …
} else {
// Create a new task with the Notion page URL in the notes section and a due date
await steps.create_taskandaddnotionurl.execute({
title: steps.trigger.event.properties.Task.title[0].plain_text,
notes: notionPageUrl,
due: steps.trigger.event.properties[“google task date format”].formula.string,
});
}
}

I noticed that the code you provided is using the arrow function syntax and is not in the proper format for a Pipedream component. Let’s convert it to the correct format and make some adjustments: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps }) { const notionPageUrl = steps.trigger.event.url; const tasks = await steps.list_tasks.$return_value; const matchingTask = tasks.find(task => task.notes.includes(notionPageUrl)); if (!matchingTask) { const title = steps.trigger.event.properties.Task.title[0].plain_text; const dueDate = steps.trigger.event.properties["google task date format"].formula.string; const url = "https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks"; const body = { title: title, due: dueDate, notes: notionPageUrl }; await axios(this, { method: "POST", url: url, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, "Content-Type": "application/json" }, data: body }); } }, }); This code should now be in the correct format for a Pipedream component. Make sure to replace this.google.$auth.oauth_access_token with the appropriate Google OAuth access token from your Google Tasks step. Give it a try and let me know if you encounter any issues.

I see that you’re trying to create or update a Google Task based on the Notion page URL. Here’s the corrected code using the Notion and Google Tasks actions available in Pipedream: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ async run({ steps }) { const notionPageUrl = steps.trigger.event.url; const tasks = steps.list_tasks.data.tasks; const matchingTask = tasks.find(task => task.notes.includes(notionPageUrl)); if (matchingTask) { // Update the existing task with the necessary information // … } else { const title = steps.trigger.event.properties.Task.title[0].plain_text; const dueDate = steps.trigger.event.properties[“google task date format”].formula.string; const url = “https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks”; const body = { title: title, due: dueDate, notes: notionPageUrl, }; await axios(this, { method: “POST”, url: url, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: body, }); } }, });

You said to Make sure to replace this.google.$auth.oauth_access_token with the appropriate Google OAuth access token from your Google Tasks step. How do I do that?

Apologies for the confusion. In the provided code, the Google OAuth access token is already being used correctly with this.google.$auth.oauth_access_token. You don’t need to replace it manually. The code will automatically use the access token from the connected Google account when the workflow is executed. Just make sure you have the Google Tasks step properly configured in your workflow.

I got this error: TypeError
Cannot read properties of undefined (reading ‘tasks’)
DETAILS

    at Object.run (file:///tmp/__pdg__/dist/code/33f0c2310d1c1b34e908b57d30b8d28c939c09d2d8344661bed6f09f07a86011/component.mjs:7:41)
    at null.executeComponent (/var/task/launch_worker.js:229:53)
    at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)

I apologize for the confusion. It seems there’s an issue with accessing the tasks property from the steps.list_tasks.data. Let’s modify the code to access the tasks correctly: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps }) { const notionPageUrl = steps.trigger.event.url; const tasks = steps.list_tasks.data.tasks || []; const matchingTask = tasks.find(task => task.notes.includes(notionPageUrl)); if (!matchingTask) { const title = steps.trigger.event.properties.Task.title[0].plain_text; const dueDate = steps.trigger.event.properties["google task date format"].formula.string; const url = "https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks"; const body = { title: title, due: dueDate, notes: notionPageUrl, }; await axios(this, { method: "POST", url: url, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: body, }); } }, }); This should fix the issue with accessing the tasks property. Give it a try and let me know if you encounter any issues.

I’m still getting this error: TypeError
Cannot read properties of undefined (reading ‘tasks’)