This topic was automatically generated from Slack. You can find the original thread here.
Hi anyone that can help. I’ve been trying to use chatgpt to create code, but it doesn’t seem to be working.
Here’s my workflow: I’m trying to 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
- A Notion trigger named “Updated Page in Database” emits an event when a page in your Notion database is updated.
- A Google Tasks action named “list_tasks” retrieves the tasks from my Google Tasks list. These are the inputs for that step: Google Tasks Account Google Tasks LiveIntegrity | Task List
Reclaim ************************** | Max Results 200 | Show Completed true | *Show Deleted false
• I also use reclaim.ai’s Google task integration. It removes anything in parenthesis from the title of the task after it’s imported into Google Tasks, so an exact match of the title won’t work to search through the tasks in order to sync due dates or completion status. I’m thinking about matching the first 7 letters to make a partial match of the title or something like that.
Any ideas or help would be incredible. I’ve been trying to figure this out for weeks, but I don’t know the first thing about coding, so I’m just doing what the bots tell me.
So, here’s the code I’ve been working with that I can’t get to work right.
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");
return;
}
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}`,
},
});
try {
if (response.data) {
console.log("Google Tasks Response:", response.data);
const tasksArray = response.data.items;
if (tasksArray && tasksArray.length > 0) {
const existingTask = tasksArray.find((task) => {
// Customize this logic to identify an existing task based on the first 7 characters of the title
const existingTitle = task.title.slice(0, 7);
const newTitle = steps.trigger.event.properties.Task.title[0].plain_text.slice(0, 7);
return existingTitle === newTitle;
});
if (existingTask) {
console.log("Found existing task:", existingTask);
const taskId = existingTask.id;
try {
const updateResponse = 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,
},
});
console.log("Update response:", updateResponse.data);
} catch (error) {
console.error("Error updating task:", taskId, error.response ? error.response.data : error);
}
} else {
console.log("Task not found. Creating a new task...");
// Create a new task in Google Tasks
const newTask = {
title: steps.trigger.event.properties.Task.title[0].plain_text,
due: isoDueDate,
notes: this.notion_page_url,
};
try {
const createResponse = 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: newTask,
});
console.log("New task created:", createResponse.data);
} catch (error) {
console.error("Error creating task:", error.response ? error.response.data : error);
}
}
}
} else {
console.log("Google Tasks Response is empty.");
}
} catch (responseError) {
console.error("Error in Google Tasks API response:", responseError);
}
console.log("Completed the component successfully.");
} catch (error) {
console.error("Error in the component:", error);
}
},
};