That’s great! The name of that step is Checking_if_Matching_Task_is_Found. How do I create step 5? This one: Add a conditional step to check the task status and perform the appropriate action in Google Tasks (create, update, or mark as complete).
To create step 5, you can add a conditional step after the Checking_if_Matching_Task_is_Found step. This step will check the task status and perform the appropriate action in Google Tasks (create, update, or mark as complete). Here’s an example of how to set up the conditional step: export default defineComponent({ async run({ steps }) { const taskStatus = steps.YOUR_PREVIOUS_STEP.taskStatus; const taskId = steps.Checking_if_Matching_Task_is_Found.taskId; const taskFound = steps.Checking_if_Matching_Task_is_Found.taskFound; const taskTitle = steps.YOUR_PREVIOUS_STEP.taskTitle; const taskDueDate = steps.YOUR_PREVIOUS_STEP.taskDueDate; if (!taskFound) { // Create a new task in Google Tasks // Use the Google Tasks API to create a new task with the taskTitle and taskDueDate } else { if (taskStatus === "completed") { // Mark the task as complete in Google Tasks // Use the Google Tasks API to mark the task with taskId as complete } else { // Update the task in Google Tasks // Use the Google Tasks API to update the task with taskId with the new taskTitle and taskDueDate } } }, }); Replace YOUR_PREVIOUS_STEP with the name of the step that provides the task status, task title, and task due date. You’ll need to use the Google Tasks API to create, update, or mark tasks as complete. You can find the API documentation here: https://developers.google.com/tasks/docs/reference/rest Also, make sure to connect your Google account and use the this.google.$auth.oauth_access_token for making API requests as mentioned in the Google app documentation.
I have a workflow that has these steps:
- Use the “Updated Page in Database” trigger from the Notion app. This will trigger the workflow when a task is updated or created in your Notion database.
- Add a code step to extract the task details and status (created, updated, or completed) from the trigger output.
- Use the “List Task Lists” action from the Google Tasks app to get the ID of the “Reclaim” task list.
- Add a custom code step to search for an existing task in the “Reclaim” list with the same title as the updated or created task in Notion. If a matching task is found, store its ID.
- Add a conditional step to check the task status and perform the appropriate action in Google Tasks (create, update, or mark as complete).
And I have it all set up, and when I run the workflow, it says that it’s a success, but then I’m not seeing the task updated in google tasks.
I’m sorry to hear that the task is not being updated in Google Tasks as expected. To help you troubleshoot the issue, I’ll need some more information about your workflow. Could you please share the code you’re using in steps 2 and 4, as well as any error messages or logs you see in the Pipedream UI when running the workflow? This will help me better understand the issue and provide a solution.
Step 2 Code is this
export default defineComponent({
async run({ steps }) {
const notionTask = steps.trigger.event;
// Extract task details
const taskTitle = steps.trigger.event.properties.Task.title[0].plain_text;
const taskDueDate = steps.trigger.event.properties["google task date format"].formula.string;
const notionPrivateUrl = steps.trigger.event.url;
// Determine task status using the "done" checkbox
const taskDone = notionTask.properties.done.checkbox;
let status;
if (taskDone) {
status = "completed";
} else {
// You can set the status to "updated" or any other value you prefer when the task is not completed
status = "updated";
}
return {
taskTitle,
taskStatus: status,
taskDueDate,
notionPrivateUrl,
};
},
});
Step 4 code is this:
export default defineComponent({
async run({ steps }) {
const taskStatus = steps.export_info.taskStatus;
const taskId = steps.Checking_if_Matching_Task_is_Found.taskId;
const taskFound = steps.Checking_if_Matching_Task_is_Found.taskFound;
const taskTitle = steps.export_info.taskTitle;
const taskDueDate = steps.export_info.taskDueDate;
if (!taskFound) {
// Create a new task in Google Tasks
// Use the Google Tasks API to create a new task with the taskTitle and taskDueDate
} else {
if (taskStatus === "completed") {
// Mark the task as complete in Google Tasks
// Use the Google Tasks API to mark the task with taskId as complete
} else {
// Update the task in Google Tasks
// Use the Google Tasks API to update the task with taskId with the new taskTitle and taskDueDate
}
}
},
});
I’m not seeing any errors, I and I don’t have and logs set up for individual steps. Step 2 is exporting the info I’m asking it to accurately, so that step seems good.
I see that in Step 4, you have comments describing the actions to be taken, but the actual code to interact with the Google Tasks API is missing. To create, update, or mark a task as complete, you’ll need to use the Google Tasks API. Here’s an updated version of your Step 4 code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google: { type: "app", app: "google", }, }, async run({ steps }) { const taskStatus = steps.export_info.taskStatus; const taskId = steps.Checking_if_Matching_Task_is_Found.taskId; const taskFound = steps.Checking_if_Matching_Task_is_Found.taskFound; const taskTitle = steps.export_info.taskTitle; const taskDueDate = steps.export_info.taskDueDate; const taskListId = "YOUR_TASK_LIST_ID"; // Replace with your Google Task List ID if (!taskFound) { // Create a new task in Google Tasks const response = await axios(this, { method: "POST", url: `https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks`, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, data: { title: taskTitle, due: taskDueDate, }, }); } else { if (taskStatus === "completed") { // Mark the task as complete in Google Tasks const response = await axios(this, { method: "POST", url: `https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks/${taskId}/toggleCompletion`, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, }); } else { // Update the task in Google Tasks const response = await axios(this, { method: "PUT", url: `https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks/${taskId}`, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, data: { title: taskTitle, due: taskDueDate, }, }); } } }, }); Make sure to replace YOUR_TASK_LIST_ID with your actual
Shouldn’t this code work to create a task if a task isn’t found? So, should these lines be different?
if (!taskFound) {
// Create a new task in Google Tasks
Yes, the code you provided checks if a task is not found (!taskFound) and then proceeds to create a new task in Google Tasks. If you could provide more context or the complete code, I can help you better understand if there’s any issue with the code or if it needs any modifications.
This is the complete code. I want it to create a task if a task isn’t found in google tasks.
import { axios } from "@pipedream/platform";
export default defineComponent({
props: {
google_tasks: {
type: "app",
app: "google_tasks",
},
},
async run({ steps }) {
const taskStatus = steps.export_info.taskStatus;
const taskId = steps.Checking_if_Matching_Task_is_Found.taskId;
const taskFound = steps.Checking_if_Matching_Task_is_Found.taskFound;
const taskTitle = steps.export_info.taskTitle;
const taskDueDate = steps.export_info.taskDueDate;
const taskListId = "Mk1hZng3dVdLeEJ6ZVZqUg"; // Replace with your Google Task List ID
if (!taskFound) {
// Create a new task in Google Tasks
const response = await axios(this, {
method: "POST",
url: `https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks`,
headers: {
Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`,
},
data: {
title: taskTitle,
due: taskDueDate,
},
});
} else {
if (taskStatus === "completed") {
// Mark the task as complete in Google Tasks
const response = await axios(this, {
method: "POST",
url: `https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks/${taskId}/toggleCompletion`,
headers: {
Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`,
},
});
} else {
// Update the task in Google Tasks
const response = await axios(this, {
method: "PUT",
url: `https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks/${taskId}`,
headers: {
Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`,
},
data: {
title: taskTitle,
due: taskDueDate,
},
});
}
}
},
});
The code you provided should work as intended. If a task is not found (!taskFound), it will create a new task in Google Tasks using the provided taskTitle and taskDueDate. If a task is found, it will either mark the task as complete if the taskStatus is “completed” or update the task with the new taskTitle and taskDueDate. If you’re experiencing any issues or need further assistance, please let me know.
The problem is that I’m just not seeing the created task in Google Tasks when I test a new task.
I’m sorry to hear that the task is not being created as expected. Let’s try to debug the issue. First, I recommend adding some logging to the code to check if the API response is successful when creating a new task. You can add console.log(response) after the API call to create a new task. Here’s the modified code snippet: ```
if (!taskFound) { // Create a new task in Google Tasks const response = await axios(this, { method: “POST”, url: https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, }, data: { title: taskTitle, due: taskDueDate, }, }); console.log(response); // Add this line to log the response }
When I used this code I got an unexpected token code error.
import { axios } from "@pipedream/platform";
export default defineComponent({
props: {
google_tasks: {
type: "app",
app: "google_tasks",
},
},
async run({ steps }) {
const taskStatus = steps.export_info.taskStatus;
const taskId = steps.Checking_if_Matching_Task_is_Found.taskId;
const taskFound = steps.Checking_if_Matching_Task_is_Found.taskFound;
const taskTitle = steps.export_info.taskTitle;
const taskDueDate = steps.export_info.taskDueDate;
const taskListId = "Mk1hZng3dVdLeEJ6ZVZqUg"; // Replace with your Google Task List ID
if (!taskFound) {
// Create a new task in Google Tasks
const response = await axios(this, {
method: "POST",
url: `https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks`,
headers: {
Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`,
},
data: {
title: taskTitle,
due: taskDueDate,
},
});
console.log(response); // Add this line to log the response
}
});
} else {
if (taskStatus === "completed") {
// Mark the task as complete in Google Tasks
const response = await axios(this, {
method: "POST",
url: `https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks/${taskId}/toggleCompletion`,
headers: {
Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`,
},
});
} else {
// Update the task in Google Tasks
const response = await axios(this, {
method: "PUT",
url: `https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks/${taskId}`,
headers: {
Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`,
},
data: {
title: taskTitle,
due: taskDueDate,
},
});
}
}
},
});
I apologize for the confusion. It seems there’s an issue with the code formatting. There’s an extra closing bracket and parenthesis that should be removed. Here’s the corrected code: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, }, async run({ steps }) { const taskStatus = steps.export_info.taskStatus; const taskId = steps.Checking_if_Matching_Task_is_Found.taskId; const taskFound = steps.Checking_if_Matching_Task_is_Found.taskFound; const taskTitle = steps.export_info.taskTitle; const taskDueDate = steps.export_info.taskDueDate; const taskListId = “Mk1hZng3dVdLeEJ6ZVZqUg”; // Replace with your Google Task List ID if (!taskFound) { // Create a new task in Google Tasks const response = await axios(this, { method: “POST”, url: https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, }, data: { title: taskTitle, due: taskDueDate, }, }); console.log(response); // Add this line to log the response } else { if (taskStatus === “completed”) { // Mark the task as complete in Google Tasks const response = await axios(this, { method: “POST”, url: https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks/${taskId}/toggleCompletion, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, }, }); } else { // Update the task in Google Tasks const response = await axios(this, { method: “PUT”, url: https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks/${taskId}, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, }, data: { title: taskTitle, due: taskDueDate, }, }); } } }, });