user-1
(User 1)
September 23, 2023, 2:09pm
121
I apologize for the inconvenience. It appears that the additional logging code didn’t work as expected. Let’s try another approach to get more detailed logs: ```
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_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”); } else { const isoDueDate = taskDueDate.toISOString(); const tasksArray = steps.list_tasks.$return_value.items; 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); } catch (error) { console.error(“Error updating task:”, taskId, error.response ? error.response.data : error); } }); await Promise.all(updateTasksPromises); } } catch (error) { console.error(“Error updating Google Task due date, notes, and completion status:”, error); throw error; } }, });
user-1
(User 1)
September 23, 2023, 2:09pm
122
: I got an error - TypeError
Cannot read properties of undefined (reading ‘map’)
at Object.run (file:///tmp/__pdg__/dist/code/c78cfcd8f9fdfc5056f363d9599f1adcead1b78ad9106f5879f021698e57f52f/component.mjs:30:48)
at null.executeComponent (/var/task/launch_worker.js:229:53)
at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)
and the logs are:
Error updating Google Task due date, notes, and completion status: at Object.run (file:///tmp/pdg /dist/code/c78cfcd8f9fdfc5056f363d9599f1adcead1b78ad9106f5879f021698e57f52f/component.mjs:30:48)
at null.executeComponent (/var/task/launch_worker.js:229:53)
at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)
Does this help?
user-1
(User 1)
September 23, 2023, 2:09pm
123
I apologize for the issue you’re experiencing. It seems that the error is caused by the tasksArray being undefined. To fix this, let’s add a check to ensure that the tasksArray is defined and has items before mapping over it. Please update your code as follows: 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_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"); } else { const isoDueDate = taskDueDate.toISOString(); const tasksArray = steps.list_tasks.$return_value.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); } catch (error) { console.error("Error updating task:", taskId, error.response ? error.response.data : error); } }); await Promise.all(updateTasksPromises); } else { console.log("No tasks found in the list."); } } } catch (error) { console.error("Error updating Google Task due date, notes, and completion status:", error); throw error; } }, }); This code checks if `
user-1
(User 1)
September 23, 2023, 2:09pm
124
It looks like you were cut off. What were you saying?
user-1
(User 1)
September 23, 2023, 2:09pm
125
Apologies for the incomplete response earlier. Here’s the updated code snippet to handle the undefined tasksArray issue: 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_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"); } else { const isoDueDate = taskDueDate.toISOString(); const tasksArray = steps.list_tasks.$return_value.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); } catch (error) { console.error("Error updating task:", taskId, error.response ? error.response.data : error); } }); await Promise.all(updateTasksPromises); } else { console.log("No tasks found in the list."); } } } catch (error) { console.error("Error updating Google Task due date, notes, and completion status:", error); throw error; } }, }); This code checks if tasksArray is defined and has items before mapping over it, which should resolve the “Cannot read properties of undefined (reading ‘map’)” error.
user-1
(User 1)
September 23, 2023, 2:09pm
126
I got this error now: No tasks found in the list.
user-1
(User 1)
September 23, 2023, 2:09pm
127
I apologize for the confusion. The “No tasks found in the list” message is not an error but an indication that there were no tasks in the specified Google Tasks list to update. Please double-check the Task List ID you provided and ensure that it contains tasks that need to be updated. If you still face issues, please provide more information about your use case, and I’ll be happy to help.
user-1
(User 1)
September 23, 2023, 2:09pm
128
The task list id is the same as the task list id from the previous step list_tasks. I’m also certain that there are tasks that need to be updated on the that task list. The id is Mk1hZng3dVdLeEJ6ZVZqUg
user-1
(User 1)
September 23, 2023, 2:09pm
129
Thank you for providing the Task List ID. I’ll update the code snippet to use the provided ID and ensure that the tasks are fetched correctly: ``` 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_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”); } else { const isoDueDate = taskDueDate.toISOString(); 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}, }, }); const tasksArray = response.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); } catch (error) { console.error(“Error updating task:”, taskId, error.response ? error.response.data : error); } }); await Promise.all(updateTasksPromises); } else { console.log("No tasks found in
user-1
(User 1)
September 23, 2023, 2:09pm
130
if there’s not a task in google tasks to match the updated page in notion, will this code create a task?
user-1
(User 1)
September 23, 2023, 2:09pm
131
The code you provided earlier does not create a new task if there’s no matching task in Google Tasks. To create a new task when there’s no matching task, you can modify the code like this: ```
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_due_date: { type: “string”, label: “Notion Due Date”, }, notion_page_url: { type: “string”, label: “Notion Page URL”, }, }, async run({ steps, $ }) { // Your existing code to update tasks // Check if tasks were found and updated if (!tasksArray || tasksArray.length === 0) { // Create a new task try { 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: “New Task from Notion”, due: isoDueDate, notes: this.notion_page_url, }, }); console.log(“New task created:”, response); } catch (error) { console.error(“Error creating new task:”, error.response ? error.response.data : error); } } }, });
user-1
(User 1)
September 23, 2023, 2:09pm
132
Can you merge this code with the previous code?
user-1
(User 1)
September 23, 2023, 2:09pm
133
Can you merge this code with the previous code? I believe it was 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”,
default: “Mk1hZng3dVdLeEJ6ZVZqUg”,
},
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”);
} else {
const isoDueDate = taskDueDate.toISOString();
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},
},
});
const tasksArray = response.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);
} catch (error) {
console.error("Error updating task:", taskId, error.response ? error.response.data : error);
}
});
await Promise.all(updateTasksPromises);
} else {
console.log("No tasks found in
user-1
(User 1)
September 23, 2023, 2:09pm
134
Here’s the merged code that updates the tasks in Google Tasks with the Notion due date and page URL, and creates a new task if no matching tasks are found: ``` 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_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”); } else { const isoDueDate = taskDueDate.toISOString(); 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}, }, }); const tasksArray = response.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); } catch (error) { console.error(“Error updating task:”, taskId, error.response ? error.response.data : error); } }); await Promise.all(updateTasksPromises); } else { console.log
user-1
(User 1)
September 23, 2023, 2:09pm
135
I added 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”,
default : “Mk1hZng3dVdLeEJ6ZVZqUg”,
},
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”);
} else {
const isoDueDate = taskDueDate.toISOString();
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},
},
});
const tasksArray = response.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);
} catch (error) {
console.error(“Error updating task:”, taskId, error.response ? error.response.data : error);
}
});
await Promise.all(updateTasksPromises);
} else {
console.log
But I got this error:
SyntaxError: Unexpected token (31:19)
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)
user-1
(User 1)
September 23, 2023, 2:09pm
136
It looks like there’s a syntax error in your code. The issue is with the template literals in the url property of the axios requests. You should use backticks (`) instead of angle brackets (<>) for template literals. Here's the corrected 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_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"); } else { const isoDueDate = taskDueDate.toISOString(); 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}, }, }); const tasksArray = response.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); } catch (error) { console.error(“Error updating task:”, taskId, error.response ? error.response.data : error);
user-1
(User 1)
September 23, 2023, 2:09pm
137
I tried that code and got this error:
SyntaxError: Unexpected token (31:19)
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)
user-1
(User 1)
September 23, 2023, 2:09pm
138
I apologize for the confusion earlier. It seems there was an issue with the formatting of the code I provided. Here’s the corrected 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_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”); } else { const isoDueDate = taskDueDate.toISOString(); 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}, }, }); const tasksArray = response.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); } catch (error) { console.error(“Error updating task:”, taskId, error.response ? error.response.data : error); } }); await Promise.all(updateTasksPromises); } } } catch (error) { console
user-1
(User 1)
September 23, 2023, 2:09pm
139
So, i tested the entire workflow with the new code and I got this error: Code Error
Unexpected token (31:19)
DETAILS
SyntaxError: Unexpected token (31:19)
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)
user-1
(User 1)
September 23, 2023, 2:09pm
140
I apologize for the inconvenience. It seems there’s an issue with the code I provided. Let’s try to fix it. Please share the code you used in your workflow so I can identify the problem and provide a solution.