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

I apologize for the inconvenience. It seems there might be an issue with accessing the properties of the response. Let’s add a check to ensure the response object is defined before accessing its properties. Please update your code with the following changes: ```
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”, }, }); if (notionTaskResponse && notionTaskResponse.data && notionTaskResponse.data.properties) { // 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”); } } else { console.log(“Error: Notion task response is not properly defined”); } }, });

I’m getting this error when I’m running my workflow after I’ve completed a task: Error - Request failed with status code 503
{“error”:{“code”:503,“message”:“The service is currently unavailable.”,“errors”:[{“message”:“The service is currently unavailable.”,“domain”:“global”,“reason”:“backendError”}],“status”:“UNAVAILABLE”}}

    at null.createError (/pipedream/dist/code/fbb3715df5ef1e64fb406e8dcc6b9fda0d9c2a81fbc5a8584761e90e0e568632/node_modules/.pnpm/axios@0.21.4/node_modules/axios/lib/core/createError.js:16:15)
    at null.settle (/pipedream/dist/code/fbb3715df5ef1e64fb406e8dcc6b9fda0d9c2a81fbc5a8584761e90e0e568632/node_modules/.pnpm/axios@0.21.4/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/pipedream/dist/code/fbb3715df5ef1e64fb406e8dcc6b9fda0d9c2a81fbc5a8584761e90e0e568632/node_modules/.pnpm/axios@0.21.4/node_modules/axios/lib/adapters/http.js:269:11)
    at IncomingMessage.emit (node:events:526:35)
    at null.endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

(google_tasks_for_changing_the_due_date)

I apologize for the inconvenience. It seems that the error you’re encountering is a 503 Service Unavailable error, which usually indicates that the server you’re trying to reach is temporarily unavailable or experiencing issues. This could be due to a temporary issue with the Google Tasks API. I recommend waiting for a short period and then trying to run the workflow again. If the issue persists, you might want to check the Google Cloud Status Dashboard for any ongoing incidents or maintenance related to the Google Tasks API. If you continue to face issues, please let me know, and I’ll be happy to help.

My workflow to watch a notion database and update google tasks is giving me errors sometimes (but not everytime) on the code step for changing the due date in google tasks.
Here is the error: Error - Request failed with status code 500
{“error”:{“code”:500,“message”:“Internal error encountered.”,“errors”:[{“message”:“Internal error encountered.”,“domain”:“global”,“reason”:“backendError”}],“status”:“INTERNAL”}}
These are the details:

at null.createError (/pipedream/dist/code/fbb3715df5ef1e64fb406e8dcc6b9fda0d9c2a81fbc5a8584761e90e0e568632/node_modules/.pnpm/axios@0.21.4/node_modules/axios/lib/core/createError.js:16:15)
    at null.settle (/pipedream/dist/code/fbb3715df5ef1e64fb406e8dcc6b9fda0d9c2a81fbc5a8584761e90e0e568632/node_modules/.pnpm/axios@0.21.4/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/pipedream/dist/code/fbb3715df5ef1e64fb406e8dcc6b9fda0d9c2a81fbc5a8584761e90e0e568632/node_modules/.pnpm/axios@0.21.4/node_modules/axios/lib/adapters/http.js:269:11)
    at IncomingMessage.emit (node:events:526:35)
    at null.endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

and 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”,
},
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;

},
});

I’m sorry to hear that you’re experiencing intermittent errors with your workflow. The error you’re encountering is a 500 Internal Server Error, which usually indicates an issue on the server side, in this case, the Google Tasks API. Since the error is not consistent, it might be a temporary issue with the Google Tasks API. You can try adding error handling to your code using a try...catch block to handle these errors more gracefully. Here’s an example of how you can modify your 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(); try { 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; } catch (error) { console.error(“Error updating Google Task due date:”, error); // You can decide how to handle the error, e.g., retry the request, send a notification, etc. } }, });

I got this error: TypeError
Cannot read properties of null (reading ‘start’)

at Object.run (file:///pipedream/dist/code/4f822db47345066051b2b37aab6baaa9f2a7e00043af310c0ca872bc258c0551/component.mjs:18:74)
    at null.executeComponent (/var/task/launch_worker.js:229:53)
    at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)

on this 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;

},
});
What’s happening there?

It looks like the error is caused by trying to access the start property of a null value in this line: const taskDueDate = new Date(steps.trigger.event.properties.Due.date.start).toISOString(); This error occurs when the steps.trigger.event.properties.Due.date object is null. To handle this situation, you can add a conditional check to ensure the object exists before accessing the start property. Here’s the modified 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 dueDateObj = steps.trigger.event.properties.Due.date; if (dueDateObj && dueDateObj.start) { const taskDueDate = new Date(dueDateObj.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; } else { console.error("Due date object is null or missing 'start' property"); // Handle the case when the due date object is null or missing the 'start' property } }, }); This code checks if dueDateObj and dueDateObj.start exist before proceeding with the task creation. If the due date object is null or missing the start property, it logs an error message and you can handle this case as needed.

Now, on this 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();

**try** {
  **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;
} **catch** (error) {
  console.error("Error updating Google Task due date:", error);
  _// You can decide how to handle the error, e.g., retry the request, send a notification, etc._
}

},
});

I get this error: RangeError
Invalid time value
DETAILS

    at Date.toISOString (null:null:null)
    at Object.run (file:///tmp/__pdg__/dist/code/be828f47996a150c2e32c02d5a6c93491c74d79e9aad9d900c7792948d799e82/component.mjs:23:56)
    at null.executeComponent (/var/task/launch_worker.js:229:53)
    at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)

Detailed/code mode
Google Tasks Account
Google Tasks
Task List ID
Mk1hZng3dVdLeEJ6ZVZqUg
Task ID
NGpVNUpwSTIyU0thLUFDMA

google_tasks_marking_complete

CONFIGURE

CODE

The provided code is a Pipedream component that updates the due date of a Google Task. It imports the axios package from @pipedream/platform and uses the google_tasks app prop for authentication. The component takes four props: google_tasks, task_list_id, task_id, and notion_due_date. In the run method, it converts the notion_due_date to an ISO string and sends a PATCH request to the Google Tasks API to update the due date of the specified task. If there’s an error during the update, it logs the error message. If you need any help or have questions, feel free to ask!

It seems like the error is caused by an invalid date value when trying to convert it to an ISO string. To fix this issue, we need to make sure that the notion_due_date prop is a valid date string. Here’s the modified 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, $ }) { try { const taskDueDate = new Date(this.notion_due_date); if (isNaN(taskDueDate.getTime())) { console.error("Invalid date value"); // Handle the case when the date value is invalid } else { const isoDueDate = taskDueDate.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: isoDueDate, }, }); return response; } } catch (error) { console.error("Error updating Google Task due date:", error); // You can decide how to handle the error, e.g., retry the request, send a notification, etc. } }, }); This code checks if the notion_due_date is a valid date before converting it to an ISO string. If the date is invalid, it logs an error message and you can handle this case as needed.

I have a workflow to watch a notion database and update google tasks based on changes in the database. I would like to add a step that adds notes to the google task. How would I do that?

To add notes to a Google Task, you can modify the existing Pipedream component that updates the Google Task. You’ll need to add a new prop for the notes and include it in the data sent in the PATCH request to the Google Tasks API. Here’s the modified 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", }, notes: { type: "string", label: "Notes", optional: true, }, }, async run({ steps, $ }) { try { const taskDueDate = new Date(this.notion_due_date); if (isNaN(taskDueDate.getTime())) { console.error("Invalid date value"); // Handle the case when the date value is invalid } else { const isoDueDate = taskDueDate.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: isoDueDate, notes: this.notes, }, }); return response; } } catch (error) { console.error("Error updating Google Task due date and notes:", error); // You can decide how to handle the error, e.g., retry the request, send a notification, etc. } }, }); This code adds a new prop called notes and includes it in the data sent in the PATCH request. If you don’t want to update the due date and only add notes, you can remove the notion_due_date prop and the related code, and only keep the notes prop in the data object.

If I wanted to make the notes the URL for the page in notion, where would I put that path in the Code?

To make the notes the URL for the page in Notion, you can modify the existing Pipedream component code that updates the Google Task. You’ll need to add a new prop for the Notion page URL and include it in the data sent in the PATCH request to the Google Tasks API. Here’s the modified 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", }, notion_page_url: { type: "string", label: "Notion Page URL", }, }, async run({ steps, $ }) { try { const taskDueDate = new Date(this.notion_due_date); if (isNaN(taskDueDate.getTime())) { console.error("Invalid date value"); // Handle the case when the date value is invalid } else { const isoDueDate = taskDueDate.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: isoDueDate, notes: this.notion_page_url, }, }); return response; } } catch (error) { console.error("Error updating Google Task due date and notes:", error); // You can decide how to handle the error, e.g., retry the request, send a notification, etc. } }, }); This code adds a new prop called notion_page_url and includes it in the data sent in the PATCH request as the notes for the Google Task.

I have a workflow to watch a notion database and update google tasks based on changes in the database. I’m not getting any errors and looks like everything worked on the deployment page, but nothing is actually changing in google tasks. What’s wrong?

It’s difficult to pinpoint the exact issue without seeing your workflow. However, I can help you troubleshoot the problem. Please make sure you’ve followed these steps: 1. Use the “Notion — Updated Page in Database” trigger. You can find it by searching for the Notion app in the trigger menu. Make sure you’ve connected your Notion account and selected the correct Database ID. 2. For updating Google Tasks, you’ll need to use the Google Tasks API within a code step. Make sure you’ve connected your Google account and have the correct Task List ID and Task ID. 3. Ensure that your code step is correctly handling the data from the Notion trigger and updating the Google Task accordingly. If you can provide more information about your workflow or the code you’re using, I can help you further.

So, I have that trigger, then my next step is to create a task when created in notion. Here’s the code for that step:
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 dueDateObj = steps.trigger.event.properties.Due.date;

**if** (dueDateObj && dueDateObj.start) {
  **const** taskDueDate = **new** Date(dueDateObj.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;
} **else** {
  console.error("Due date object is null or missing 'start' property");
  _// Handle the case when the due date object is null or missing the 'start' property_
}

},
});

The next step is List_tasks in google tasks. I have the max results at 400 and show completed as false. The next step is to update google tasks with the URL, different due date. Here’s that 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”,
},
notion_page_url: {
type: “string”,
label: “Notion Page URL”,
},
},
async run({ steps, $ }) {
try {
const taskDueDate = new Date(this.notion_due_date);
if (isNaN(taskDueDate.getTime())) {
console.error(“Invalid date value”);
// Handle the case when the date value is invalid
} else {
const isoDueDate = taskDueDate.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: isoDueDate,
notes: this.notion_page_url,
},
});

    **return** response;
  }
} **catch** (error) {
  console.error("Error updating Google Task due date and notes:", error);
  _// You can decide how to handle the error, e.g., retry the request, send a notification, etc._
}

},
});
The final step is a node to mark tasks as complete. Here’s the code for that one:
export default defineComponent({
async run({ steps, $ }) {
const tasks = steps.list_tasks.$return_value;
const updatedTasks = [];

**for** (**const** task **of** tasks) {
  _// Update the task with Completed set to true_
  task.completed = **true**;
  updatedTasks.push(task);
}

**return** updatedTasks;

},
});

It looks like you have a workflow that consists of several steps: 1. A trigger step. 2. A step to create a task in Google Tasks when a new task is created in Notion. 3. A step to list tasks in Google Tasks. 4. A step to update Google Tasks with a different due date and Notion page URL. 5. A final step to mark tasks as complete. Your code seems to be well-structured, and each step is performing its intended task. If you encounter any issues or need further assistance, please let me know.

Thanks! But, the issue I’m having is that the workflow doesn’t seem to actually be updating google tasks.