How to Modify Code to Filter the Correct Google Task List in a Notion Database Update Workflow?

that code provides no exports at all. The export is grayed out at the bottom of the step.

I apologize for the confusion earlier. I noticed an issue in the code related to checking the response for items. Here’s the corrected code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google_tasks: { type: "app", app: "google_tasks", }, taskListId: { type: "string", label: "Task List ID", default: "Mk1hZng3dVdLeEJ6ZVZqUg", }, }, async run({ steps, $ }) { const notionURL = steps.trigger.event.url; const response = await axios($, { url: `https://www.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks`, headers: { Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`, }, }); console.log("Response:", response); if (response.data && response.data.items) { const existingTasks = response.data.items.filter(task => task.notes === notionURL); return { filteredTasks: existingTasks }; } else { console.log("No items found in the response."); } } }); This code should now properly filter the tasks based on the notionURL and return the filtered tasks as a step export.

The log is saying there’s no items found in the response.

I apologize for the confusion earlier. Let’s add some additional logging to help debug the issue. Please update your code as follows: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, taskListId: { type: “string”, label: “Task List ID”, default: “Mk1hZng3dVdLeEJ6ZVZqUg”, }, }, async run({ steps, $ }) { const notionURL = steps.trigger.event.url; const response = await axios($, { url: https://www.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, }, }); console.log(“Response:”, response); if (response.data && response.data.items) { const existingTasks = response.data.items.filter(task => task.notes === notionURL); return { filteredTasks: existingTasks }; } else { console.log(“No items found in the response. Response data:”, response.data); } } });

One log says this: No items found in the response. Response data: undefined

The other log shows this: 9/20/2023, 9:36:48 AM
Response: {
kind: 'tasks#tasks',
etag: '"LTEyOTUyNDE2MDM"',
nextPageToken: 'CgsIyuaiqAYQmO2CHBoQUzh4R0hXdUVfYkRvcmNfdw==',
items: [
{
kind: 'tasks#task',
id: 'MURrRVFzT20xbklPVEFEOA',
etag: '"LTEyOTUyMzcyMjc"',
title: "testing the filter to see if it finds something that's there. ",
updated: '2023-09-20T13:34:04.000Z',
selfLink: 'https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks/MURrRVFzT20xbklPVEFEOA',
position: '00000000000000000000',
status: 'needsAction',
due: '2023-09-19T00:00:00.000Z',
links: []
},
{
kind: 'tasks#task',
id: 'RGV4Q3plQ2xoVHdpTUpMdg',
etag: '"LTEyOTY2NTQzOTE"',
title: 'Come up with a generosity communication plan for integrity draft',
updated: '2023-09-20T13:10:27.000Z',
selfLink: 'https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks/RGV4Q3plQ2xoVHdpTUpMdg',
position: '00000000000000000004',
notes: 'https://www.notion.so/Come-up-with-a-generosity-communication-plan-for-integrity-draft-type-work-7bc0700733c24cc6845a073e4869c249',
status: 'needsAction',
due: '2023-09-21T00:00:00.000Z',
links: []
},
{
kind: 'tasks#task',
id: 'cTdGRnQ4UW4xSkpYNFEwcg',
etag: '"LTEyOTY2NTU2OTM"',
title: 'Come up with a generosity communication plan for integrity draft',
updated: '2023-09-20T13:10:26.000Z',
selfLink: 'https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks/cTdGRnQ4UW4xSkpYNFEwcg',
position: '00000000000000000003',
notes: 'https://www.notion.so/Come-up-with-a-generosity-communication-plan-for-integrity-draft-type-work-7bc0700733c24cc6845a073e4869c249',
status: 'needsAction',
due: '2023-09-21T00:00:00.000Z',
links: []
},
{

I apologize for the issue you’re experiencing. It seems that the response data is undefined, which might indicate an issue with the API request or an unexpected response format. Let’s add more detailed logging to help identify the problem. Please update your code as follows: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, taskListId: { type: “string”, label: “Task List ID”, default: “Mk1hZng3dVdLeEJ6ZVZqUg”, }, }, async run({ steps, $ }) { const notionURL = steps.trigger.event.url; try { const response = await axios($, { url: https://www.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, }, }); console.log(“Response:”, response); if (response.data && response.data.items) { const existingTasks = response.data.items.filter(task => task.notes === notionURL); return { filteredTasks: existingTasks }; } else { console.log(“No items found in the response. Response data:”, response.data); } } catch (error) { console.error(“Error during API request:”, error); } }, });

It looks like you have a log with a response containing a list of tasks. If you want to filter these tasks based on a specific condition, you can use the Filter app in Pipedream. Here’s an example of how you can filter tasks that have the status “needsAction”: export default defineComponent({ async run({ steps, $ }) { const tasks = steps.previous_step_name.items; // Replace "previous_step_name" with the name of the step that produced the tasks const needsActionTasks = tasks.filter(task => task.status === "needsAction"); return needsActionTasks; }, }); Replace steps.previous_step_name with the name of the step that produced the tasks in your workflow. This code will filter the tasks and return only those with the status “needsAction”.

I want this filtered code to actually export an array of filtered tasks. Currently it’s not doing that.

import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    google_tasks: {
      type: "app",
      app: "google_tasks",
    },
    taskListId: {
      type: "string",
      label: "Task List ID",
      default: "Mk1hZng3dVdLeEJ6ZVZqUg",
    },
  },
  async run({ steps, $ }) {
    const notionURL = steps.trigger.event.url;
    const response = await axios($, {
      url: `https://www.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks`,
      headers: {
        Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`,
      },
    });

    console.log("Response:", response);

    if (response.data && response.data.items) {
      const existingTasks = response.data.items.filter(task => task.notes === notionURL);
      return { filteredTasks: existingTasks };
    } else {
      console.log("No items found in the response. Response data:", response.data);
    }
  }
});

I see that you want to export an array of filtered tasks. In your current code, you’re returning an object with a filteredTasks property. To return the array directly, you can update the return statement like this: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google_tasks: { type: "app", app: "google_tasks", }, taskListId: { type: "string", label: "Task List ID", default: "Mk1hZng3dVdLeEJ6ZVZqUg", }, }, async run({ steps, $ }) { const notionURL = steps.trigger.event.url; const response = await axios($, { url: `https://www.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks`, headers: { Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`, }, }); console.log("Response:", response); if (response.data && response.data.items) { const existingTasks = response.data.items.filter(task => task.notes === notionURL); return existingTasks; // Return the array directly } else { console.log("No items found in the response. Response data:", response.data); } } }); Now, the run method will return the existingTasks array directly.

Could I filter this based on there being anything in the notes property in google tasks instead of it being a specific step prop?

Yes, you can filter tasks based on whether the notes property has any content. You can modify the existingTasks filter in your code like this: ```
const existingTasks = response.data.items.filter(task => task.notes && task.notes.length > 0);

Can you insert that code snippet into this code? import { axios } from@pipedream/platform”;

export default defineComponent({
props: {
google_tasks: {
type: “app”,
app: “google_tasks”,
},
taskListId: {
type: “string”,
label: “Task List ID”,
default: “Mk1hZng3dVdLeEJ6ZVZqUg”,
},
},
async run({ steps, $ }) {
const notionURL = steps.trigger.event.url;
const response = await axios($, {
url: https://www.googleapis.com/tasks/v1/lists/${**this**.taskListId}/tasks,
headers: {
Authorization: Bearer ${**this**.google_tasks.$auth.oauth_access_token},
},
});

console.log(“Response:“, response);

**if** (response.data && response.data.items) {
  **const** existingTasks = response.data.items.filter(task => task.notes === notionURL);
  **return** existingTasks; _// Return the array directly_

Sure, I’ve updated the code snippet to filter tasks based on whether the notes property has any content: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google_tasks: { type: "app", app: "google_tasks", }, taskListId: { type: "string", label: "Task List ID", default: "Mk1hZng3dVdLeEJ6ZVZqUg", }, }, async run({ steps, $ }) { const response = await axios($, { url: `https://www.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks`, headers: { Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`, }, }); console.log("Response:", response); if (response.data && response.data.items) { const existingTasks = response.data.items.filter(task => task.notes && task.notes.length > 0); return existingTasks; // Return the array directly } else { console.log("No items found in the response. Response data:", response.data); } } }); Now, the existingTasks array will contain tasks with non-empty notes.

This code keeps returning no items, although I know from my previous list_tasks google tasks step that there should be at least one task that is filtered. What’s could be going on?

This code keeps returning no items, although I know from my previous list_tasks google tasks step that there should be at least one task that is filtered. What’s could be going on?

import { axios } from@pipedream/platform”;

export default defineComponent({
props: {
google_tasks: {
type: “app”,
app: “google_tasks”,
},
taskListId: {
type: “string”,
label: “Task List ID”,
default: “Mk1hZng3dVdLeEJ6ZVZqUg”,
},
},
async run({ steps, $ }) {
const response = await axios($, {
url: https://www.googleapis.com/tasks/v1/lists/${**this**.taskListId}/tasks,
headers: {
Authorization: Bearer ${**this**.google_tasks.$auth.oauth_access_token},
},
});

console.log(“Response:“, response);

**if** (response.data && response.data.items) {
  **const** existingTasks = response.data.items.filter(task => task.notes && task.notes.length > 0);
  **return** existingTasks; _// Return the array directly_
} **else** {
  console.log(“No items found in the response. Response data:“, response.data);
}

}
});

I see that you’re trying to filter tasks with non-empty notes. If you’re not getting any results, it’s possible that there’s an issue with the filtering condition or the data returned from the API. To debug this, let’s log the tasks before filtering and see if there’s any issue with the data. Update your code like this: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, taskListId: { type: “string”, label: “Task List ID”, default: “Mk1hZng3dVdLeEJ6ZVZqUg”, }, }, async run({ steps, $ }) { const response = await axios($, { url: https://www.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, }, }); console.log(“Response:”, response); if (response.data && response.data.items) { console.log(“Tasks before filtering:”, response.data.items); const existingTasks = response.data.items.filter(task => task.notes && task.notes.length > 0); return existingTasks; } else { console.log(“No items found in the response. Response data:”, response.data); } } });

This shows up in the logs as a response: kind: ‘tasks#task’,
id: ‘MURrRVFzT20xbklPVEFEOA’,
etag: ’“LTEyOTUyMzcyMjc”’,
title: “testing the filter to see if it finds something that’s there. “,
updated: ‘2023-09-20T13:34:04.000Z’,
selfLink: ‘https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks/MURrRVFzT20xbklPVEFEOA’,
position: ‘00000000000000000002’,
status: ‘needsAction’,
due: ‘2023-09-19T00:00:00.000Z’,
links: []
},
{
But the filter still says this: No items found in the response. Response data: undefined
This task though, clearly, doesn’t have a note.

I noticed that you’re using && and > in your code, which are HTML entities. They should be replaced with their actual symbols && and >. Here’s the corrected code: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, taskListId: { type: “string”, label: “Task List ID”, default: “Mk1hZng3dVdLeEJ6ZVZqUg”, }, }, async run({ steps, $ }) { const response = await axios($, { url: https://www.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, }, }); console.log(“Response:”, response); if (response.data && response.data.items) { console.log(“Tasks before filtering:”, response.data.items); const existingTasks = response.data.items.filter(task => task.notes && task.notes.length > 0); return existingTasks; } else { console.log(“No items found in the response. Response data:”, response.data); } } });

The filter still didn’t find any items.