How Can I Successfully Use ChatGPT to Update Google Task List When Updating Tasks in Notion?

Posted thread to Discourse: How to Troubleshoot Issues with Using ChatGPT for Syncing Notion and Google Tasks Updates?

I have a workflow that updates my google tasks when I update my tasks in a notion database. I trigger is also firing when I create a new page in the database and right now I don’t have the workflow creating a new task when a new page is created in notion. I would like for the workflow to do that, but I’m not sure what step to add to get it to do that. Here are the steps:
◦ Trigger - updated page in database.

check_completion_status jsnode
export default defineComponent({
  async run({ steps }) {
    const isTaskComplete = steps.trigger.event.properties.done.checkbox;

    if (isTaskComplete) {
      // Task is marked as complete in Notion, proceed to the next step
      return { taskComplete: true };
    } else {
      // Task is not marked as complete, proceed to the next step
      return { taskComplete: false };
    }
  },
});

• Notion_extraction_for_due_dates jsnode

export default defineComponent({
  props: {
    notionPrivateUrl: {
      type: "string",
      label: "Notion Private URL",
    },
    dueDate: {
      type: "string",
      label: "Due Date",
    },
    title: {
      type: "string",
      label: "Title",
    },
  },
  async run({ steps }) {
    const privateUrl = this.notionPrivateUrl;
    const dueDate = this.dueDate;
    const title = this.title;

    return { title, dueDate, privateUrl };
  },
});

• List_tasks google tasks step
• check_if_matching_task_is_found

import { URL } from "url";

export default defineComponent({
  props: {
    privateUrl: {
      type: "string",
      label: "Notion Private URL",
    },
  },
  async run({ steps }) {
    const notionPrivateUrl = new URL(this.privateUrl);
    const tasks = steps.list_tasks.$return_value;

    console.log("Notion Private URL:", notionPrivateUrl);
    console.log("Tasks:", tasks);

    const matchingTask = tasks.find((task) => {
      if (task.notes) {
        try {
          const taskUrl = new URL(task.notes);
          return taskUrl.pathname === notionPrivateUrl.pathname;
        } catch (error) {
          console.error("Error parsing URL:", error);
        }
      }
      return false;
    });

    if (matchingTask) {
      console.log("Matching Task:", matchingTask);
      return { taskId: matchingTask.id, taskTitle: matchingTask.title, taskFound: true };
    } else {
      console.log("No matching task found");
      return { taskFound: false };
    }
  },
});
◦ update_task google tasks step

To create a new Google Task when a new page is created in Notion, you can add a conditional step after the check_if_matching_task_is_found step to check if a matching task was found. If not, create a new Google Task using the “Google — Create Task” action. Here’s how you can modify your workflow: 1. Add a new code step after the check_if_matching_task_is_found step. Name it check_if_task_needs_creation. Use the following code: export default defineComponent({ async run({ steps }) { const taskFound = steps.check_if_matching_task_is_found.taskFound; if (!taskFound) { // No matching task found, proceed to create a new task return { createNewTask: true }; } else { // Matching task found, no need to create a new task return { createNewTask: false }; } }, }); 2. Add the “Google — Create Task” action after the check_if_task_needs_creation step. Connect your Google account and fill in the required fields using the data from the Notion_extraction_for_due_dates step. For example, use steps.Notion_extraction_for_due_dates.title for the task title and steps.Notion_extraction_for_due_dates.privateUrl for the task notes. 3. Click on the gear icon on the top-right corner of the “Google — Create Task” action and select “Conditional Execution”. Set the condition to steps.check_if_task_needs_creation.createNewTask. This will ensure that the action only runs when a new task needs to be created. Now, your workflow will create a new Google Task when a new page is created in Notion and no matching task is found.

I don’t see a gear icon in the “Google Tasks - Create_task” action

Apologies for the confusion. In Pipedream, you can add a conditional execution to a code step instead. After the check_if_task_needs_creation step, add a new code step named create_task_if_needed. Use the following code: export default defineComponent({ async run({ steps }) { if (steps.check_if_task_needs_creation.createNewTask) { // Add the "Google Tasks - Create_task" action here // and configure it with the required fields // using data from the `Notion_extraction_for_due_dates` step. } else { // If no new task needs to be created, just return an empty object return {}; } }, }); Then, add the “Google Tasks - Create_task” action within the if block of the create_task_if_needed step. This will ensure that the action only runs when a new task needs to be created.

How do I add the “Google Tasks - Create_task” action within the if block of the create_task_if_needed step?

I apologize for the confusion earlier. You cannot directly add the “Google Tasks - Create_task” action within the if block of a code step. Instead, you can use the Google Tasks API to create a task within the code step. Here’s how you can modify the create_task_if_needed step: 1. Add the following import at the beginning of your code: import { axios } from "@pipedream/platform"; 2. Modify the create_task_if_needed step as follows: export default defineComponent({ async run({ steps }) { if (steps.check_if_task_needs_creation.createNewTask) { // Use the Google Tasks API to create a new task const url = `https://tasks.googleapis.com/tasks/v1/lists/@default/tasks`; const response = await axios(this, { method: "POST", url: url, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: { title: steps.Notion_extraction_for_due_dates.title, notes: steps.Notion_extraction_for_due_dates.privateUrl, // Add any other required fields for the task }, }); return { newTask: response.data }; } else { // If no new task needs to be created, just return an empty object return {}; } }, }); This code will use the Google Tasks API to create a new task when the condition steps.check_if_task_needs_creation.createNewTask is true. Make sure to connect your Google account and pass the required authentication details in the Authorization header.

my final step update_task won’t complete in my workflow as I test it because the task I’m using is a new task that doesn’t already exist in google tasks. What should I do?

It seems like you need to create the task first before updating it. You can use the Google Tasks API to create a new task within a code step. Here’s an example of how you can create a new task and then update it: 1. Add the following import at the beginning of your code: import { axios } from "@pipedream/platform"; 2. Modify your workflow by adding a new code step to create a new task: export default defineComponent({ async run({ steps }) { // Use the Google Tasks API to create a new task const createTaskUrl = `https://tasks.googleapis.com/tasks/v1/lists/@default/tasks`; const createTaskResponse = await axios(this, { method: "POST", url: createTaskUrl, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: { title: "Your task title", notes: "Your task notes", // Add any other required fields for the task }, }); // Store the created task ID const taskId = createTaskResponse.data.id; // Now update the task using the taskId const updateTaskUrl = `https://tasks.googleapis.com/tasks/v1/lists/@default/tasks/${taskId}`; const updateTaskResponse = await axios(this, { method: "PUT", url: updateTaskUrl, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: { // Update the task with the desired properties }, }); return { updatedTask: updateTaskResponse.data }; }, }); This code will create a new task and then update it using the Google Tasks API. Make sure to connect your Google account and pass the required authentication details in the Authorization header. Replace the task title, notes, and update properties with the appropriate values from your workflow.

This step “create_task_if_needed” doesn’t seem to be creating a task. import { axios } from@pipedream/platform”;

export default defineComponent({
async run({ steps }) {
if (steps.check_if_task_needs_creation.createNewTask) {
// Use the Google Tasks API to create a new task
const url = https://tasks.googleapis.com/tasks/v1/lists/@default/tasks;
const response = await axios(this, {
method: “POST”,
url: url,
headers: {
Authorization: Bearer ${**this**.google.$auth.oauth_access_token},
“Content-Type”: “application/json”,
},
data: {
title: steps.Notion_extraction_for_due_dates.title,
notes: steps.Notion_extraction_for_due_dates.privateUrl,
due: steps.Notion_Extraction_for_Due_Dates.$return_value.dueDate
// Add any other required fields for the task
},
});
return { newTask: response.data };
} else {
// If no new task needs to be created, just return an empty object
return {};
}
},
});

The code you provided seems to be correct for creating a new task using the Google Tasks API. However, it’s important to ensure that the condition steps.check_if_task_needs_creation.createNewTask is being met for the task creation process to execute. If the condition is not met, the code will return an empty object, and no task will be created. Please double-check the check_if_task_needs_creation step in your workflow to ensure it’s correctly determining whether a new task needs to be created. If you’re still having issues, you can add some debugging statements, like console.log() to print the values of variables and the condition, which can help you identify the issue.

This is what’s returned on that step: steps.check_if_task_needs_creation{1}
$return_value{1}
createNewTask:
true

Since the steps.check_if_task_needs_creation.createNewTask value is true, the task creation code should be executed. If the task is still not being created, you can add some debugging statements to help identify the issue. For example, you can log the response from the Google Tasks API: ```
if (steps.check_if_task_needs_creation.createNewTask) { // … const response = await axios(this, { /** … **/ }); console.log(“Task creation response:”, response.data); return { newTask: response.data }; } else { // … }

This is the response from the create_task_if_needed step steps.create_task_if_needed{1}
$return_value{0}

It seems that the create_task_if_needed step is not returning the expected output. To debug this issue, you can add console.log() statements to log the values of variables and the response from the Google Tasks API. Update your code like this: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps }) { if (steps.check_if_task_needs_creation.createNewTask) { const url = `https://tasks.googleapis.com/tasks/v1/lists/@default/tasks`; const response = await axios(this, { method: "POST", url: url, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: { title: steps.Notion_extraction_for_due_dates.title, notes: steps.Notion_extraction_for_due_dates.privateUrl, due: steps.Notion_Extraction_for_Due_Dates.$return_value.dueDate, }, }); console.log("Task creation response:", response); return { newTask: response }; } else { return {}; } }, }); After adding the console.log() statement, run the workflow again and check the Pipedream logs for the “Task creation response” log entry. This should provide more information about the response from the Google Tasks API and help you identify the issue. If you still face issues, please share any error messages or additional details from the logs, so I can help you further.

Where do I find the Pipedream logs for the “Task creation response” log entry?

To find the Pipedream logs for the “Task creation response” log entry, follow these steps: 1. Go to your Pipedream workflow’s main page. 2. Click on the “Logs” tab located below the workflow canvas. 3. Look for the “Task creation response” log entry in the logs. The logs display the output of each step in your workflow, including any console.log() statements you’ve added. If you see the “Task creation response” log entry, you can inspect the details to help you debug any issues with the task creation process.

I can’t find it.

I apologize for the confusion. Let’s try a different approach to help you find the “Task creation response” log entry. 1. Go to your Pipedream workflow’s main page. 2. Click on the “History” tab located below the workflow canvas. 3. Find the most recent execution of your workflow and click on it. 4. In the execution details, you should see a list of steps. Click on the step where you added the console.log("Task creation response:", response); statement. 5. In the step details, you should see the “Task creation response” log entry along with the response data. If you still can’t find the log entry, please double-check that you’ve added the console.log() statement in the correct step and that the workflow has been executed after adding the statement. If you need further assistance, feel free to ask.

I added it to the code like this: import { axios } from@pipedream/platform”;

export default defineComponent({
async run({ steps }) {
if (steps.check_if_task_needs_creation.createNewTask) {
const url = https://tasks.googleapis.com/tasks/v1/lists/@default/tasks;
const response = await axios(this, {
method: “POST”,
url: url,
headers: {
Authorization: Bearer ${**this**.google.$auth.oauth_access_token},
“Content-Type”: “application/json”,
},
data: {
title: steps.Notion_extraction_for_due_dates.title,
notes: steps.Notion_extraction_for_due_dates.privateUrl,
due: steps.Notion_Extraction_for_Due_Dates.$return_value.dueDate,
},
});
console.log(“Task creation response:”, response);
return { newTask: response };
} else {
return {};
}
},
But I’m not getting any logs
});