To create a workflow that watches your Notion database for new tasks and creates a matching task in Google Tasks, follow these steps: 1. Use the Notion — New Page in Database trigger. - Search for the Notion app from the trigger menu - Select the New Page in Database trigger - Connect your Notion account - Select a Database ID or pass a string from a previous step - Follow the instructions on the trigger configuration screen. You may need to generate a test event from Notion to get real data to test your workflow. 2. Add a Code step to extract the task title, due date, and Notion URL from the trigger data. export default defineComponent({ async run({ steps }) { const page = steps.trigger.event; const title = page.properties.Title.title[0].plain_text; const dueDate = page.properties.Due_Date.date.start; const notionUrl = page.url; return { title, dueDate, notionUrl }; }, });
3. Add the Google Tasks — Create Task action. - Search for the Google Tasks app from the step menu - Select the Create Task action - Connect your Google account - Select a Task List ID or pass a string from a previous step - Set the Task Title to {{steps.code.title}}
- Set the Due Date to {{steps.code.dueDate}}
- Set the Notes to {{steps.code.notionUrl}}
- At the bottom of the step, click Test to run the action and test the configuration. This workflow will now watch for new tasks in your Notion database and create a matching task in Google Tasks with the title, due date, and Notion URL as notes.
On step 2, can you write the code to include that data as props to configure instead of directly in the code?
Sure, I can modify the code in step 2 to use props for the task title, due date, and Notion URL. Here’s the updated code: ```
export default defineComponent({ props: { pageTitle: { type: “string”, label: “Task Title”, }, pageDueDate: { type: “string”, label: “Task Due Date”, }, pageUrl: { type: “string”, label: “Notion URL”, }, }, async run({ steps }) { const title = this.pageTitle; const dueDate = this.pageDueDate; const notionUrl = this.pageUrl; return { title, dueDate, notionUrl }; }, });
One issue with this workflow is that I would like for it to only create a task in google tasks if that task doesn’t already exist in google tasks.
My hope with that is that I wouldn’t be creating duplicate tasks in google tasks.
To ensure that a task is only created in Google Tasks if it doesn’t already exist, you can add a step to search for existing tasks with the same title before creating a new one. Here’s how you can modify the workflow: 1. Add a Code step after the step that extracts the task title, due date, and Notion URL. Name this step searchTasks
. In this step, we’ll call the Google Tasks API to search for tasks with the same title: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google: { type: "app", app: "google", }, taskListId: { type: "string", label: "Task List ID", }, title: { type: "string", label: "Task Title", }, }, async run({ $ }) { const url = `https://tasks.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks`; const { data } = await axios($, { method: "GET", url, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, }); const existingTask = data.items.find((task) => task.title === this.title); return { existingTask }; }, });
2. Modify the Google Tasks — Create Task action step to add a conditional check. Only create a new task if steps.searchTasks.existingTask
is undefined
. You can use the if
property in the step settings: ```
yaml if: steps.searchTasks.existingTask === undefined
To ensure you don’t create duplicate tasks in Google Tasks, you can add a step to search for existing tasks with the same title before creating a new one. Here’s how you can modify the workflow: 1. After the code step that extracts the task title, due date, and Notion URL, add the Google Tasks — List Tasks action. - Search for the Google Tasks app from the step menu - Select the List Tasks action - Connect your Google account - Select a Task List ID or pass a string from a previous step - At the bottom of the step, click Test to run the action and test the configuration 2. Add another Code step to check if a task with the same title already exists: export default defineComponent({ async run({ steps }) { const existingTasks = steps.list_tasks.data.items; const taskTitle = steps.code.title; const taskExists = existingTasks.some(task => task.title === taskTitle); return { taskExists }; }, });
3. Add a conditional step to check if taskExists
is false before creating a new task in Google Tasks. If it’s false, proceed to the Google Tasks — Create Task action as described in the previous answer. If it’s true, you can either end the workflow or add any other action you’d like to perform when a duplicate task is detected. This modified workflow will now check for existing tasks with the same title in Google Tasks and only create a new task if it doesn’t already exist.
I like that answer, but I would like for the step to search for existing tasks with the same first 5 characters in the title instead of the entire title matching before creating a new one.
To modify the workflow to search for existing tasks with the same first 5 characters in the title, you can update the searchTasks
step in the following way: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google: { type: “app”, app: “google”, }, taskListId: { type: “string”, label: “Task List ID”, }, title: { type: “string”, label: “Task Title”, }, }, async run({ $ }) { const url = https://tasks.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks
; const { data } = await axios($, { method: “GET”, url, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}
, }, }); const titlePrefix = this.title.slice(0, 5); const existingTask = data.items.find((task) => task.title.slice(0, 5) === titlePrefix); return { existingTask }; }, });
I see the google api is for the google account. I need it to be for the google tasks api for this to work. Can you switch those in the code?
I apologize for the confusion. To modify the code for the Google Tasks API, you can update the axios
request in the run
method like this: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google: { type: “app”, app: “google”, }, taskListId: { type: “string”, label: “Task List ID”, }, title: { type: “string”, label: “Task Title”, }, }, async run({ $ }) { const url = https://tasks.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks
; const { data } = await axios($, { method: “GET”, url, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}
, }, }); const titlePrefix = this.title.slice(0, 5); const existingTask = data.items.find((task) => task.title.slice(0, 5) === titlePrefix); return { existingTask }; }, });
What string should I use for the “task title” prop?
To use the “task title” prop in the Pipedream component, you can define it within the props
object like this: props: { taskTitle: { type: "string", label: "Task Title", }, // other props... },
Then, within the run
method, you can access the task title using this.taskTitle
.
I have this code in the search_tasks step, but I’m not sure what to put in the “Task title” import { axios } from “@pipedream/platform”;
export default defineComponent({
props: {
google: {
type: “app”,
app: “google_tasks”,
},
taskListId: {
type: “string”,
label: “Task List ID”,
},
title: {
type: “string”,
label: “Task Title”,
},
},
async run({ $ }) {
const url = https://tasks.googleapis.com/tasks/v1/lists/${**this**.taskListId}/tasks
;
const { data } = await axios($, {
method: “GET”,
url,
headers: {
Authorization: Bearer ${**this**.google.$auth.oauth_access_token}
,
},
});
**const** titlePrefix = **this**.title.slice(0, 5);
**const** existingTask = data.items.find((task) => task.title.slice(0, 5) === titlePrefix);
**return** { existingTask };
},
});
In the code you provided, the “Task title” is represented by the title
prop. To use this component, you’ll need to provide a value for the title
prop when you add this step to your workflow. The value you provide for the title
prop will be used to search for existing tasks with the same first 5 characters in their titles. When you add this step to your workflow, you should see a form field labeled “Task Title” where you can input the desired task title to be used for the search.
Ok, I see that, but because I’m wanting that step to search through all the titles in google tasks, how would I set that up?
To search through all the titles in Google Tasks, you can modify the existing code to loop through all the tasks and compare their titles. Here’s an updated version of the code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google: { type: "app", app: "google_tasks", }, taskListId: { type: "string", label: "Task List ID", }, title: { type: "string", label: "Task Title", }, }, async run({ $ }) { const url = `https://tasks.googleapis.com/tasks/v1/lists/${this.taskListId}/tasks`; const { data } = await axios($, { method: "GET", url, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, }); const matchingTasks = data.items.filter((task) => task.title === this.title); return { matchingTasks }; }, });
This code will now search through all the tasks in the specified task list and return an array of tasks with titles that match the provided title
prop.
Does this code take out the part about searching for the first 5 characters, like how this code is constructed? const titlePrefix = this.title.slice(0, 5);
const existingTask = data.items.find((task) => task.title.slice(0, 5) === titlePrefix);
return { existingTask };
Yes, the updated code I provided earlier removes the part about searching for the first 5 characters. Instead, it searches for tasks with titles that exactly match the provided title
prop. Here’s the relevant part of the updated code: const matchingTasks = data.items.filter((task) => task.title === this.title); return { matchingTasks };
This code will return an array of tasks with titles that exactly match the provided title
prop, instead of just comparing the first 5 characters.
Can you create a code that will search an array of tasks with titles that match the first 5 characters or is that not possible in an array?