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

I tried to use this code: const { Client } = require(‘@notionhq/client’);
const notion = new Client({ auth: process.env.NOTION_API_KEY });
const databaseId = ‘1165ab1d5fdb4a88b6bcc45ae0d2d9d7’;
const filteredRows = async () => {
const response = await notion.databases.query({
database_id: databaseId,
filter: {
property: “done”{{steps.trigger.event.properties.done}},
checkbox: { equals: true{{steps.trigger.event.properties.done.checkbox}}
}
},
});
return response;
}
But I got this error: SyntaxError
Unexpected token c in JSON at position 0

pi I only have one other step and that is the trigger that goes off when a database page is updated

I’m using the query_database step in notion after a trigger that goes when a database page is updated. I have it configured with my notion account and the database ID of All Tasks [UB]
1165ab1d-5fdb-4a88-b6bc-c45ae0d2d9d7. The filter is { “filter”: { “property”: “done”, “checkbox”: { “does_not_equal”: true } } }, but I’m getting this APIResponseError
body failed validation. Fix one: body.filter.or should be defined, instead was undefined. body.filter.and should be defined, instead was undefined. body.filter.title should be defined, instead was undefined. body.filter.rich_text should be defined, instead was undefined. body.filter.number should be defined, instead was undefined. body.filter.checkbox should be defined, instead was undefined. body.filter.select should be defined, instead was undefined. body.filter.multi_select should be defined, instead was undefined. body.filter.status should be defined, instead was undefined. body.filter.date should be defined, instead was undefined. body.filter.people should be defined, instead was undefined. body.filter.files should be defined, instead was undefined. body.filter.url should be defined, instead was undefined. body.filter.email should be defined, instead was undefined. body.filter.phone_number should be defined, instead was undefined. body.filter.relation should be defined, instead was undefined. body.filter.created_by should be defined, instead was undefined. body.filter.created_time should be defined, instead was undefined. body.filter.last_edited_by should be defined, instead was undefined. body.filter.last_edited_time should be defined, instead was undefined. body.filter.formula should be defined, instead was undefined. body.filter.unique_id should be defined, instead was undefined. body.filter.rollup should be defined, instead was undefined.

I apologize for the confusion earlier. To fix the APIResponseError you’re encountering, please update the filter in the Notion “Query Database” action within your Pipedream workflow. The filter should be in the following format: ```
on { “property”: “done”, “checkbox”: { “does_not_equal”: true } }

That filter gives me this error: SyntaxError
Unexpected token o in JSON at position 0

I apologize for the confusion earlier. It seems the filter JSON format was incorrect. Since you’re using the Notion “Query Database” action in your Pipedream workflow, please update the filter configuration as follows: 1. Go to your Pipedream workflow. 2. Click on the Notion “Query Database” action step. 3. Update the “Filter” field with the correct JSON format: ```
on { “property”: “done”, “checkbox”: { “does_not_equal”: true } }

It looked like you got cut off as you were writing this code and giving me directions, what’s the full code? 4. Compare the Notion database and Google Tasks list, and update the Google Tasks list to match the Notion database if they’re different.

Here’s a starting point for the workflow. You’ll need to customize it to match your specific Notion database and Google Tasks list structure:

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

export default defineComponent({
 props: {
   notion: {
     type: "app",
     app: "notion",
   },
   google_tasks: {
     type: "app",
     app: "google_tasks",
   },
   database_id: {
     type: "string",
     label: "Notion Database ID",
   },
   task_list_id: {
     type: "string",
     label: "Google Task List ID",
   },
 },
 async run({ steps, $ }) {
   // Fetch the Notion database content
   const notionDatabase = await this.notion.sdk().pages.query({
     database_id: this.database_id,
   });

   // Fetch the Google Tasks list
   const googleTasksResponse = await axios(this, {
     method: "GET",
     url: `https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks`,
     headers: {
       Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`,
     },
   });
   const googleTasksList = googleTasksResponse.data.items;

   // Compare the Notion database and Google

Apologies for the confusion earlier. Here’s a complete example of a Pipedream workflow that compares a Notion database with a Google Tasks list and updates the Google Tasks list to match the Notion database: ``` import { axios } from “@pipedream/platform”; export default defineComponent({ props: { notion: { type: “app”, app: “notion”, }, google_tasks: { type: “app”, app: “google_tasks”, }, database_id: { type: “string”, label: “Notion Database ID”, }, task_list_id: { type: “string”, label: “Google Task List ID”, }, }, async run({ steps, $ }) { // Fetch the Notion database content const notionDatabase = await this.notion.sdk().databases.query({ database_id: this.database_id, }); // Fetch the Google Tasks list const googleTasksResponse = await axios(this, { method: “GET”, url: https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, }, }); const googleTasksList = googleTasksResponse.data.items; // Compare the Notion database and Google Tasks list, and update the Google Tasks list if they’re different for (const notionPage of notionDatabase.results) { const notionTaskTitle = notionPage.properties.Name.title[0].plain_text; const notionTaskDone = notionPage.properties.Done.checkbox; const googleTask = googleTasksList.find( (task) => task.title === notionTaskTitle ); if (googleTask) { if (googleTask.status === “completed” && !notionTaskDone) { // Update the Google Task to match the Notion database await axios(this, { method: “POST”, url: https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks/${googleTask.id}, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: { status: “needsAction”, }, }); } } else { // Create a new Google Task to match the Not

This code seems unfinished

I apologize for the incomplete code earlier. Here’s the complete Pipedream workflow code to compare a Notion database with a Google Tasks list and update the Google Tasks list to match the Notion database: ``` import { axios } from “@pipedream/platform”; export default defineComponent({ props: { notion: { type: “app”, app: “notion”, }, google_tasks: { type: “app”, app: “google_tasks”, }, database_id: { type: “string”, label: “Notion Database ID”, }, task_list_id: { type: “string”, label: “Google Task List ID”, }, }, async run({ steps, $ }) { // Fetch the Notion database content const notionDatabase = await this.notion.sdk().databases.query({ database_id: this.database_id, }); // Fetch the Google Tasks list const googleTasksResponse = await axios(this, { method: “GET”, url: https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, }, }); const googleTasksList = googleTasksResponse.data.items; // Compare the Notion database and Google Tasks list, and update the Google Tasks list if they’re different for (const notionPage of notionDatabase.results) { const notionTaskTitle = notionPage.properties.Name.title[0].plain_text; const notionTaskDone = notionPage.properties.Done.checkbox; const googleTask = googleTasksList.find( (task) => task.title === notionTaskTitle ); if (googleTask) { if (googleTask.status === “completed” && !notionTaskDone) { // Update the Google Task to match the Notion database await axios(this, { method: “POST”, url: https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks/${googleTask.id}, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: { status: “needsAction”, }, }); } } else { // Create a new Google Task to match the Notion

That code gave me this error: Code Error
Unexpected token (29:15)
DETAILS

SyntaxError: Unexpected token (29: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 code. It seems there’s a syntax issue. Please share the code you’re using so I can help identify and fix the problem.

Here’s the code: import { axios } from@pipedream/platform”;
export default defineComponent({
props: {
notion: {
type: “app”,
app: “notion”,
},
google_tasks: {
type: “app”,
app: “google_tasks”,
},
database_id: {
type: “string”,
label: “Notion Database ID”,
},
task_list_id: {
type: “string”,
label: “Google Task List ID”,
},
},
async run({ steps, $ }) {
// Fetch the Notion database content
const notionDatabase = await this.notion.sdk().databases.query({
database_id: this.database_id,
});
// Fetch the Google Tasks list
const googleTasksResponse = await axios(this, {
method: “GET”,
url: https://tasks.googleapis.com/tasks/v1/lists/${**this**.task_list_id}/tasks,
headers: {
Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token},
},
});
const googleTasksList = googleTasksResponse.data.items;
// Compare the Notion database and Google Tasks list, and update the Google Tasks list if they’re different
for (const notionPage of notionDatabase.results) {
const notionTaskTitle = notionPage.properties.Name.title[0].plain_text;
const notionTaskDone = notionPage.properties.Done.checkbox;
const googleTask = googleTasksList.find(
(task) => task.title === notionTaskTitle
);
if (googleTask) {
if (googleTask.status === “completed” && !notionTaskDone) {
// Update the Google Task to match the Notion database
await axios(this, {
method: “POST”,
url: https://tasks.googleapis.com/tasks/v1/lists/${**this**.task_list_id}/tasks/${googleTask.id},
headers: {
Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token},
“Content-Type”: “application/json”,
},
data: {
status: “needsAction”,
},
});
}
} else {
// Create a new Google Task to match the Notion

I see the issue in your code. There’s a syntax error with the template literals in the url property of the axios requests. You should use backticks () instead of angle brackets (<>) for the template literals. Here's the corrected code: ``` import { axios } from "@pipedream/platform"; export default defineComponent({ props: { notion: { type: "app", app: "notion", }, google_tasks: { type: "app", app: "google_tasks", }, database_id: { type: "string", label: "Notion Database ID", }, task_list_id: { type: "string", label: "Google Task List ID", }, }, async run({ steps, $ }) { // Fetch the Notion database content const notionDatabase = await this.notion.sdk().databases.query({ database_id: this.database_id, }); // Fetch the Google Tasks list const googleTasksResponse = await axios(this, { method: "GET", url: https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks`, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, }, }); const googleTasksList = googleTasksResponse.data.items; // Compare the Notion database and Google Tasks list, and update the Google Tasks list if they’re different for (const notionPage of notionDatabase.results) { const notionTaskTitle = notionPage.properties.Name.title[0].plain_text; const notionTaskDone = notionPage.properties.Done.checkbox; const googleTask = googleTasksList.find( (task) => task.title === notionTaskTitle ); if (googleTask) { if (googleTask.status === “completed” && !notionTaskDone) { // Update the Google Task to match the Notion database await axios(this, { method: “POST”, url: https://tasks.googleapis.com/tasks/v1/lists/${this.task_list_id}/tasks/${googleTask.id}, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: { status: “needsAction”, }, }); } } else {

This code is giving me an API response error saying the API token is invalid: import { axios } from@pipedream/platform”;
import { Client } from@notionhq/client”; // Use import for Notion client

export default defineComponent({
props: {
notion: {
type: “app”,
app: “notion”,
},
google_tasks: {
type: “app”,
app: “google_tasks”,
},
database_id: {
type: “string”,
label: “Notion Database ID”,
},
task_list_id: {
type: “string”,
label: “Google Task List ID”,
},
},
async run({ steps, $ }) {
// Initialize the Notion client with your API key
const notion = new Client({ auth: process.env.NOTION_API_KEY });

// Fetch the Notion database content
const notionDatabase = await notion.databases.query({
database_id: this.database_id,
});

// Fetch the Google Tasks list
const googleTasksResponse = await axios(this, {
method: “GET”,
url: https://tasks.googleapis.com/tasks/v1/lists/${**this**.task_list_id}/tasks,
headers: {
Authorization: Bearer ${**this**.google_tasks.$auth.oauth_access_token},
},
});
const googleTasksList = googleTasksResponse.data.items;

// Compare the Notion database and Google Tasks list, and update the Google Tasks list if they’re different
for (const notionPage of notionDatabase.results) {
const notionTaskTitle = notionPage.properties.Name.title[0].plain_text;
const notionTaskDone = notionPage.properties.Done.checkbox;
const googleTask = googleTasksList.find(
(task) => task.title === notionTaskTitle
);
if (googleTask) {
if (googleTask.status === “completed” && !notionTaskDone) {
// Update the Google Task to match the Notion database
await axios(this, {
method: “POST”,
url: https://tasks.googleapis.com/tasks/v1/lists/${**this**.task_list_id}/tasks/${googleTask.id},
headers: {
Authorization: Bearer ${**this**.google_tasks.$auth.oauth_access_token},
“Content-Type”: “application/json”,
},
data: {
status: “needsAction”,
},
});
}
}
}
}
});

It seems like there might be an issue with the Notion API key. Please double-check that you have entered the correct API key for Notion. You should be using this.notion.$auth.oauth_access_token instead of process.env.NOTION_API_KEY. Update the Notion client initialization as follows: ```
const notion = new Client({ auth: this.notion.$auth.oauth_access_token });

I’m not getting a type error on the properties of undefined (reading items" on this code import { axios } from@pipedream/platform”;
import { Client } from@notionhq/client”; // Use import for Notion client

export default defineComponent({
props: {
notion: {
type: “app”,
app: “notion”,
},
google_tasks: {
type: “app”,
app: “google_tasks”,
},
database_id: {
type: “string”,
label: “Notion Database ID”,
},
task_list_id: {
type: “string”,
label: “Google Task List ID”,
},
},
async run({ steps, $ }) {
// Initialize the Notion client with your API key
const notion = new Client({ auth: this.notion.$auth.oauth_access_token});

// Fetch the Notion database content
const notionDatabase = await notion.databases.query({
database_id: this.database_id,
});

// Fetch the Google Tasks list
const googleTasksResponse = await axios(this, {
method: “GET”,
url: https://tasks.googleapis.com/tasks/v1/lists/${**this**.task_list_id}/tasks,
headers: {
Authorization: Bearer ${**this**.google_tasks.$auth.oauth_access_token},
},
});
const googleTasksList = googleTasksResponse.data.items;

// Compare the Notion database and Google Tasks list, and update the Google Tasks list if they’re different
for (const notionPage of notionDatabase.results) {
const notionTaskTitle = notionPage.properties.Name.title[0].plain_text;
const notionTaskDone = notionPage.properties.Done.checkbox;
const googleTask = googleTasksList.find(
(task) => task.title === notionTaskTitle
);
if (googleTask) {
if (googleTask.status === “completed” && !notionTaskDone) {
// Update the Google Task to match the Notion database
await axios(this, {
method: “POST”,
url: https://tasks.googleapis.com/tasks/v1/lists/${**this**.task_list_id}/tasks/${googleTask.id},
headers: {
Authorization: Bearer ${**this**.google_tasks.$auth.oauth_access_token},
“Content-Type”: “application/json”,
},
data: {
status: “needsAction”,
},
});
}
}
}
}
});

I’m now getting a type error on the properties of undefined (reading items" on this code import { axios } from@pipedream/platform”;
import { Client } from@notionhq/client”; // Use import for Notion client

export default defineComponent({
props: {
notion: {
type: “app”,
app: “notion”,
},
google_tasks: {
type: “app”,
app: “google_tasks”,
},
database_id: {
type: “string”,
label: “Notion Database ID”,
},
task_list_id: {
type: “string”,
label: “Google Task List ID”,
},
},
async run({ steps, $ }) {
// Initialize the Notion client with your API key
const notion = new Client({ auth: this.notion.$auth.oauth_access_token});

// Fetch the Notion database content
const notionDatabase = await notion.databases.query({
database_id: this.database_id,
});

// Fetch the Google Tasks list
const googleTasksResponse = await axios(this, {
method: “GET”,
url: https://tasks.googleapis.com/tasks/v1/lists/${**this**.task_list_id}/tasks,
headers: {
Authorization: Bearer ${**this**.google_tasks.$auth.oauth_access_token},
},
});
const googleTasksList = googleTasksResponse.data.items;

// Compare the Notion database and Google Tasks list, and update the Google Tasks list if they’re different
for (const notionPage of notionDatabase.results) {
const notionTaskTitle = notionPage.properties.Name.title[0].plain_text;
const notionTaskDone = notionPage.properties.Done.checkbox;
const googleTask = googleTasksList.find(
(task) => task.title === notionTaskTitle
);
if (googleTask) {
if (googleTask.status === “completed” && !notionTaskDone) {
// Update the Google Task to match the Notion database
await axios(this, {
method: “POST”,
url: https://tasks.googleapis.com/tasks/v1/lists/${**this**.task_list_id}/tasks/${googleTask.id},
headers: {
Authorization: Bearer ${**this**.google_tasks.$auth.oauth_access_token},
“Content-Type”: “application/json”,
},
data: {
status: “needsAction”,
},
});
}
}
}
}
});

It looks like the issue is with this line of code: const googleTasksList = googleTasksResponse.data.items; The error occurs because googleTasksResponse.data might not have the items property. To fix this, you can add a conditional check before accessing the items property: const googleTasksList = googleTasksResponse.data?.items || []; This will ensure that if items is not present in googleTasksResponse.data, an empty array will be assigned to googleTasksList.

I’m working on a workflow that will update my google tasks lists when I update my tasks in notion. (I’m using Thomas Frank’s Ultimate Brain for reference). It consists of these elements

  1. A Notion trigger named “Updated Page in Database” that emits an event when a page in your Notion database is updated.
  2. A Google Tasks action named “list_tasks” retrieves the tasks from your Google Tasks list. The code updates each task’s due date, notes, and completion status in the tasks array obtained from the “list_tasks” step. It also should create a task if one doesn’t exist in Google Tasks.
    The code in the final step is this:
    import { axios } from@pipedream/platform”;

export default {
props: {
google_tasks: {
type: “app”,
app: “google_tasks”,
},
task_list_id: {
type: “string”,
label: “Task List ID”,
default: “Mk1hZng3dVdLeEJ6ZVZqUg”,
},
notion_due_date: {
type: “string”,
label: “Notion Due Date”,
},
notion_page_url: {
type: “string”,
label: “Notes”,
},
},
async run({ steps, $ }) {
try {
console.log(“Starting the component…”);

  **const** taskDueDate = **new** Date(**this**.notion_due_date);
  **if** (isNaN(taskDueDate.getTime())) {
    console.error("Invalid date value");
  } **else** {
    **const** isoDueDate = taskDueDate.toISOString();

    _// Debugging: Log HTTP request to Google Tasks API_
    console.log("HTTP Request to Google Tasks API:", {
      method: "GET",
      url: `https://tasks.googleapis.com/tasks/v1/lists/${**this**.task_list_id}/tasks`,
      headers: {
        Authorization: `Bearer ${**this**.google_tasks.$auth.oauth_access_token}`,
      },
    });

    **const** response = **await** axios(**this**, {
      method: "GET",
      url: `https://tasks.googleapis.com/tasks/v1/lists/${**this**.task_list_id}/tasks`,
      headers: {
        Authorization: `Bearer ${**this**.google_tasks.$auth.oauth_access_token}`,
      },
    });

    **if** (response.data) {
      console.log("Google Tasks Response:", response.data);
      **const** tasksArray = response.data.items;
      **if** (tasksArray && tasksArray.length > 0) {
        **const** updateTasksPromises = tasksArray.map(**async** (task) => {
          console.log("Task:", task);
          **const** taskId = task.id;
          **try** {
            **const** response = **await** axios(**this**, {
              method: "PATCH",
              url: `https://tasks.googleapis.com/tasks/v1/lists/${**this**.task_list_id}/tasks/${taskId}`,
              headers: {
                Authorization: `Bearer ${**this**.google_tasks.$auth.oauth_access_token}`,
                "Content-Type": "application/json",
              },
              data: {
                due: isoDueDate,
                notes: **this**.notion_page_url,
                status: "completed",
              },
            });

            console.log("Update response:", response.data);
          } **catch** (error) {
            console.error("Error updating task:", taskId, error.response ? error.response.data : error);
          }
        });

        **await** Promise.all(updateTasksPromises);
      }
    } **else** {
      console.error("Google Tasks Response is empty.");
    }
  }

  console.log("Completed the component successfully.");
} **catch** (error) {
  console.error("Error in the component:", error);
}

},
};

and I’m getting this in the logs: 9/15/2023, 10:17:47 AM
Starting the component...

9/15/2023, 10:17:47 AM
HTTP Request to Google Tasks API: {
method: 'GET',
url: 'https://tasks.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks',
headers: {
Authorization: 'Bearer ya29.a0AfB_byBasmaqDSWH5sPokuYtHVs65cEgJaKKFC2pUM_GlieYMWu_mEVmmdxGEy7U1g2OVs8cZRUoafZobBN_jbkE7NDOhBeJlds2d_sHbeXQY0TLC1zuQlUsdBX2csKOUeq-KdO0o6qacY1vzRar4VhwVrwPLfBVOPabaCgYKAfMSARMSFQGOcNnC_G5OMuj0yjs8V0RpqpF52Q0171'
}
}

9/15/2023, 10:17:48 AM
Google Tasks Response is empty.
9/15/2023, 10:17:48 AM
Completed the component successfully.

Why is the notion task not showing up in google tasks?