How to Fix Errors While Integrating Google Tasks Update Upon Modification in Notion Using Node.js Code?

I put this code in, but it doesn’t seem to be doing any actions in the exports. The title of the task isn’t in the export and the due date isn’t there either. Then, when I go over to my google tasks account, there’s no task there. Any idea?

This is the code:
import { axios } from@pipedream/platform”;

export default defineComponent({
props: {
google_tasks: {
type: “app”,
app: “google_tasks”,
},
task_list_id: {
type: “string”,
label: “Task List ID”,
default: “Mk1hZng3dVdLeEJ6ZVZqUg”,
},
notion: {
type: “app”,
app: “notion”,
},
database_id: {
type: “string”,
label: “Notion Database ID”,
default: “1165ab1d5fdb4a88b6bcc45ae0d2d9d7”,
},
},
async run({ steps, $ }) {
// Extract the updated task information from the Notion trigger step
const updatedTask = steps.trigger.event;

_// Check the changes in the task (e.g. new task, due date change, or task completion)_
_// and perform the corresponding actions in Google Tasks using the Google Tasks API_
**return** **await** axios($, {
  url: `https://www.googleapis.com/tasks/v1/users/@me/lists`,
  headers: {
    Authorization: `Bearer ${**this**.google_tasks.$auth.oauth_access_token}`,
  },
})

},
})

I apologize for the confusion earlier. The provided code was just a template and didn’t include the specific logic to handle the Notion tasks and interact with the Google Tasks API. Let’s try to build a more complete solution for your use case. First, you’ll need a trigger to listen for changes in your Notion database. You can use the “New Database Item” or “Updated Database Item” trigger from the Notion app in Pipedream. Once you have the trigger set up, you can add a code step to handle the task creation, update, or completion in Google Tasks. Here’s an example code step that demonstrates how to create a new task in Google Tasks with a title and due date: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google_tasks: { type: "app", app: "google_tasks", }, task_list_id: { type: "string", label: "Task List ID", default: "MTM5MjA3NzE5NQ", }, }, async run({ steps, $ }) { // Extract the updated task information from the Notion trigger step const updatedTask = steps.trigger.event; // Set the task title and due date from the Notion task const taskTitle = updatedTask.title; const taskDueDate = updatedTask.due_date; // Create a new task in Google Tasks with the title and due date 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: taskTitle, due: taskDueDate, }, }); // Return the created task data return response; }, }); Replace the default value for task_list_id with your actual Google Task List ID. This code assumes that the Notion trigger step provides the task title and due date in the title and due_date properties, respectively. You might need to adjust the property names based on your Notion database structure. This example only covers task creation. You’ll need to add more logic to handle task updates and

Would be better to add the logic for task due date updates and completion updates in a separate step or in the same code in the previous step?

It depends on your preference and the complexity of the logic. If the logic for handling task due date updates and completion updates is relatively simple, you can include it in the same code step. This keeps the workflow concise and easier to understand. However, if the logic becomes more complex, it might be better to separate the logic into different code steps. This way, you can isolate and manage each part of the logic independently, making it easier to maintain and debug. In summary, you can choose either approach based on your preference and the complexity of the logic.

When I enter the code I get an invalid argument code:
import { axios } from@pipedream/platform”;

export default defineComponent({
props: {
google_tasks: {
type: “app”,
app: “google_tasks”,
},
task_list_id: {
type: “string”,
label: “Reclaim”,
default: “Mk1hZng3dVdLeEJ6ZVZqUg”,
},
},
async run({ steps, $ }) {
// Extract the updated task information from the Notion trigger step
const updatedTask = steps.trigger.event;

_// Set the task title and due date from the Notion task_
**const** taskTitle = steps.trigger.event.properties.Task.title[0].plain_text;
**const** taskDueDate = steps.trigger.event.properties.Due.date.start;

_// Create a new task in Google Tasks with the title and due date_
**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: taskTitle,
    due: taskDueDate,
  },
});

_// Return the created task data_
**return** response;

},
});

I apologize for the formatting issues in the code. Here’s the corrected version: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, task_list_id: { type: “string”, label: “Reclaim”, default: “Mk1hZng3dVdLeEJ6ZVZqUg”, }, }, async run({ steps, $ }) { // Extract the updated task information from the Notion trigger step const updatedTask = steps.trigger.event; // Set the task title and due date from the Notion task const taskTitle = steps.trigger.event.properties.Task.title[0].plain_text; const taskDueDate = steps.trigger.event.properties.Due.date.start; // Create a new task in Google Tasks with the title and due date 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: taskTitle, due: taskDueDate, }, }); // Return the created task data return response; }, });

I’m getting the same error. I believe the “steps.trigger.event.properties.Due.date.start” is in the wrong format for google tasks. It needs to be in some sort of RJS date format?

You’re correct that the date format might be causing the issue. Google Tasks API expects the due date to be in RFC 3339 format. You can convert the date from Notion to the required format using the toISOString() method in JavaScript. Here’s the updated code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google_tasks: { type: "app", app: "google_tasks", }, task_list_id: { type: "string", label: "Reclaim", default: "Mk1hZng3dVdLeEJ6ZVZqUg", }, }, async run({ steps, $ }) { const updatedTask = steps.trigger.event; const taskTitle = steps.trigger.event.properties.Task.title[0].plain_text; const taskDueDate = new Date(steps.trigger.event.properties.Due.date.start).toISOString(); 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: taskTitle, due: taskDueDate, }, }); return response; }, }); This code converts the taskDueDate to RFC 3339 format using toISOString(). Try using this updated code and let me know if it resolves the issue.

Can you create a code for a separate step that updates the due date in google tasks when the Due.date.start changes in the notion database?

Sure, I can help you with that. Here’s a code snippet for a Pipedream component that updates the due date in Google Tasks when the Due.date.start changes in the Notion database. You’ll need the Google Tasks task ID and the updated due date from the Notion trigger step: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google_tasks: { type: "app", app: "google_tasks", }, task_list_id: { type: "string", label: "Task List ID", }, task_id: { type: "string", label: "Task ID", }, notion_due_date: { type: "string", label: "Notion Due Date", }, }, async run({ steps, $ }) { const taskDueDate = new Date(this.notion_due_date).toISOString(); const response = await axios(this, { method: "PATCH", url: `https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks/${this.task_id}`, headers: { Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: { due: taskDueDate, }, }); return response; }, }); Replace the task_list_id and task_id with the appropriate values from your Google Tasks, and set the notion_due_date prop to the updated Due.date.start value from the Notion trigger step. This component will update the due date of the specified task in Google Tasks.

How could I create a variable for the task id in the above code to be able to update the id from a list_tasks step in google tasks?

To create a variable for the task ID and update it from a list_tasks step in Google Tasks, you can add a new prop for the task_id in the component code. Here’s the updated code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google_tasks: { type: "app", app: "google_tasks", }, task_list_id: { type: "string", label: "Task List ID", }, task_id: { type: "string", label: "Task ID", }, notion_due_date: { type: "string", label: "Notion Due Date", }, }, async run({ steps, $ }) { const taskDueDate = new Date(this.notion_due_date).toISOString(); const response = await axios(this, { method: "PATCH", url: `https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks/${this.task_id}`, headers: { Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: { due: taskDueDate, }, }); return response; }, }); Now, when you use this component in your workflow, you can pass the task_id from the list_tasks step to the task_id prop in this component. This will allow you to update the due date for the specified task in Google Tasks.

based on the previous information, I want to add another code step to watch the notion database for when tasks are marked as complete and then mark them as complete in google tasks as well.

To watch the Notion database for when tasks are marked as complete and then mark them as complete in Google Tasks, you can create a new Pipedream component that uses the Notion “Updated Page in Database” trigger and the Google Tasks API to update the task status. First, use the Notion “Updated Page in Database” trigger to watch for changes in your Notion database. You can follow the instructions in this source: https://pipedream.com/apps/notion/triggers/updated-page Next, add a code step to check if the task is marked as complete in Notion and update the task status in Google Tasks. Here’s an example component: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google_tasks: { type: "app", app: "google_tasks", }, task_list_id: { type: "string", label: "Task List ID", }, notion_task_id: { type: "string", label: "Notion Task ID", }, notion_task_status: { type: "string", label: "Notion Task Status", }, }, async run({ steps, $ }) { if (this.notion_task_status === "completed") { const response = await axios(this, { method: "PATCH", url: `https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks/${this.notion_task_id}`, headers: { Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: { status: "completed", }, }); return response; } else { console.log("Task is not marked as complete in Notion"); } }, }); Replace the task_list_id and notion_task_id with the appropriate values from your Google Tasks and Notion database, and set the notion_task_status prop to the updated task status from the Notion trigger step. This component will update the task status in Google Tasks if the task is marked as complete in Notion.

This code doesn’t seem to be working in my workflow to mark tasks as complete in google tasks when they are marked complete in notion. What do I need to change in the code?
import { axios } from@pipedream/platform”;

export default defineComponent({
props: {
google_tasks: {
type: “app”,
app: “google_tasks”,
},
task_list_id: {
type: “string”,
label: “Task List ID”,
},
notion_task_id: {
type: “string”,
label: “Notion Task ID”,
},
notion_task_status: {
type: “string”,
label: “Notion Task Status”,
},
},
async run({ steps, $ }) {
if (this.notion_task_status === “completed”) {
const response = await axios(this, {
method: “PATCH”,
url: https://tasks.googleapis.com/tasks/v1/lists/${**this**.task_list_id}/tasks/${**this**.notion_task_id},
headers: {
Authorization: Bearer ${**this**.google_tasks.$auth.oauth_access_token},
“Content-Type”: “application/json”,
},
data: {
status: “completed”,
},
});

  **return** response;
} **else** {
  console.log("Task is not marked as complete in Notion");
}

},
});

I apologize for the confusion. It seems the code provided earlier might not be working as expected. Let’s try to modify the code to better handle the task completion synchronization between Notion and Google Tasks. First, you’ll need to use the Notion API to retrieve the updated task information, including its status. You can use the Notion “Updated Page in Database” trigger to get the page ID of the updated task. Then, use the Notion API to fetch the task details and check if it’s marked as complete. If the task is marked as complete in Notion, you can then update the corresponding task in Google Tasks. Here’s an updated version of the code: ``` import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, notion: { type: “app”, app: “notion”, }, task_list_id: { type: “string”, label: “Task List ID”, }, notion_page_id: { type: “string”, label: “Notion Page ID”, }, }, async run({ steps, $ }) { // Fetch the Notion task details const notionTaskResponse = await axios(this, { method: “GET”, url: https://api.notion.com/v1/pages/${this.notion_page_id}, headers: { Authorization: Bearer ${this.notion.$auth.oauth_access_token}, “Notion-Version”: “2021-08-16”, }, }); // Check if the task is marked as complete in Notion const notionTaskStatus = notionTaskResponse.properties.Status.select.name; if (notionTaskStatus === “completed”) { // Update the task status in Google Tasks const response = await axios(this, { method: “PATCH”, url: https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks/${this.notion_page_id}, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: { status: “completed”, }, }); return response; } else { console.log(“Task is not marked as complete in Notion”); } },

When I used that code, this is the error I got:

SyntaxError: Unexpected token (25:15)
    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.expect (/var/task/node_modules/acorn/dist/acorn.js:692:28)
    at pp$3.parseObj (/var/task/node_modules/acorn/dist/acorn.js:2563:14)
    at pp$3.parseExprAtom (/var/task/node_modules/acorn/dist/acorn.js:2302:19)
    at anonymous.parseExprAtom (/var/task/node_modules/acorn-node/lib/dynamic-import/index.js:77:117)
    at anonymous.parseExprAtom (/var/task/node_modules/acorn-node/lib/import-meta/index.js:27:102)
    at pp$3.parseExprSubscripts (/var/task/node_modules/acorn/dist/acorn.js:2129:21)
    at pp$3.parseMaybeUnary (/var/task/node_modules/acorn/dist/acorn.js:2106:19)
    at anonymous.parseMaybeUnary (/var/task/node_modules/acorn-node/lib/private-class-elements/index.js:122:54)

I apologize for the error in the provided code. It seems there’s a syntax issue. Let me correct it for you: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, notion: { type: “app”, app: “notion”, }, task_list_id: { type: “string”, label: “Task List ID”, }, notion_page_id: { type: “string”, label: “Notion Page ID”, }, }, async run({ steps, $ }) { // Fetch the Notion task details const notionTaskResponse = await axios(this, { method: “GET”, url: https://api.notion.com/v1/pages/${this.notion_page_id}, headers: { Authorization: Bearer ${this.notion.$auth.oauth_access_token}, “Notion-Version”: “2021-08-16”, }, }); // Check if the task is marked as complete in Notion const notionTaskStatus = notionTaskResponse.data.properties.Status.select.name; if (notionTaskStatus === “completed”) { // Update the task status in Google Tasks const response = await axios(this, { method: “PATCH”, url: https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks/${this.notion_page_id}, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: { status: “completed”, }, }); return response.data; } else { console.log(“Task is not marked as complete in Notion”); } }, });

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

at Object.run (file:///tmp/__pdg__/dist/code/b053c736c3b8f4a31ea6490c345a2718f5869e80e524ab72e2f744e29b68b1da/component.mjs:34:54)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at null.executeComponent (/var/task/launch_worker.js:229:22)
    at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)