I apologize for the inconvenience. Let’s try a different approach to access the tasks data. Please update your code as follows: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps }) { const notionPageUrl = steps.trigger.event.url; const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; const matchingTask = tasks.find(task => task.notes.includes(notionPageUrl)); if (!matchingTask) { const title = steps.trigger.event.properties.Task.title[0].plain_text; const dueDate = steps.trigger.event.properties["google task date format"].formula.string; const url = "https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks"; const body = { title: title, due: dueDate, notes: notionPageUrl, }; await axios(this, { method: "POST", url: url, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: body, }); } }, }); This code checks if tasksData and tasksData.tasks are defined before assigning the value to tasks. If you still encounter issues, please let me know.
I’m now getting this error: TypeError
Cannot read properties of undefined (reading ‘$auth’)
DETAILS
at Object.run (file:///tmp/__pdg__/dist/code/950ef841d54a872ed2e7e638671db8e9d6b929b2e17b93b64376da8fd9fb27b7/component.mjs:26:48)
at null.executeComponent (/var/task/launch_worker.js:229:53)
at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)
Timestamp
9/18/2023, 4:51:12 PMDuration
214ms
create_taskandaddnotionurl
CONFIGURE
RESULTS
update_google_tasks_due_dates
CONFIGURE
CODE
update_google_tasks_completetion_status
CONFIGURE
CODE
google_tasks_updating_notes_duedates_completion
CONFIGURE
CODE
RESULTS
I apologize for the issue you’re facing. It seems there’s a problem with accessing the $auth property. Let’s update the code to use the correct authentication method: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps }) { const notionPageUrl = steps.trigger.event.url; const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; const matchingTask = tasks.find(task => task.notes.includes(notionPageUrl)); if (!matchingTask) { const title = steps.trigger.event.properties.Task.title[0].plain_text; const dueDate = steps.trigger.event.properties["google task date format"].formula.string; const url = "https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks"; const body = { title: title, due: dueDate, notes: notionPageUrl, }; await axios(this, { method: "POST", url: url, headers: { Authorization: `Bearer ${steps.google_auth.oauth_access_token}`, "Content-Type": "application/json", }, data: body, }); } }, }); In this updated code, I replaced this.google.$auth.oauth_access_token with steps.google_auth.oauth_access_token. Please try this updated code and let me know if you still encounter any issues.
This is the current error: TypeError
Cannot read properties of undefined (reading ‘oauth_access_token’)
DETAILS
at Object.run (file:///tmp/__pdg__/dist/code/fa7333f3eec64ce7176aee67227aab0099eb0166ec0fba3af926fa7d215a3804/component.mjs:26:54)
at null.executeComponent (/var/task/launch_worker.js:229:53)
at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)
I apologize for the confusion. It seems there’s an issue with accessing the oauth_access_token. To resolve this, please make sure you have properly set up the Google authentication in your workflow. You can follow these steps: 1. Add a new step in your workflow and search for the “Google” app. 2. Select the “OAuth2” authentication option. 3. Connect your Google account or use an existing connected account. 4. Name this step google_auth. Now, update your code to use the correct authentication token: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps }) { const notionPageUrl = steps.trigger.event.url; const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; const matchingTask = tasks.find(task => task.notes.includes(notionPageUrl)); if (!matchingTask) { const title = steps.trigger.event.properties.Task.title[0].plain_text; const dueDate = steps.trigger.event.properties["google task date format"].formula.string; const url = "https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks"; const body = { title: title, due: dueDate, notes: notionPageUrl, }; await axios(this, { method: "POST", url: url, headers: { Authorization: `Bearer ${steps.google_auth.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: body, }); } }, }); In this updated code, I replaced steps.google_auth.oauth_access_token with steps.google_auth.$auth.oauth_access_token. Please try this updated code and let me know if you still encounter any issues.
I can’t find an “OAuth2” authentication option under the google app
I apologize for the confusion earlier. In Pipedream, you don’t need to explicitly select an “OAuth2” authentication option for the Google app. When you add a new step in your workflow and search for the “Google” app, you’ll be prompted to connect your Google account or use an existing connected account. This process will handle the OAuth2 authentication for you. Once you’ve connected your Google account, you can access the OAuth access token within your code using this.google.$auth.oauth_access_token. For example: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google: { type: “app”, app: “google”, }, }, async run({ steps, $ }) { const url = “https://www.googleapis.com/oauth2/v1/userinfo”; const response = await axios(this, { url: url, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}, }, }); return response; }, });
I created that step, it worked, and I renamed it, but I got this error: TypeError
Cannot read properties of undefined (reading ‘oauth_access_token’)
I apologize for the confusion. It seems there’s still an issue with accessing the oauth_access_token. To help you better, can you please provide the following information: 1. The name of the step you created and connected to your Google account. 2. The updated code you’re using in your component. Once I have this information, I’ll be able to assist you in resolving the issue.
This is the name of the step: google_auth
and this is the updated code:
import { axios } from "@pipedream/platform";
export default defineComponent({
async run({ steps }) {
const notionPageUrl = steps.trigger.event.url;
const tasksData = steps.list_tasks.data;
const tasks = tasksData && tasksData.tasks ? tasksData.tasks : [];
const matchingTask = tasks.find(task => task.notes.includes(notionPageUrl));
if (!matchingTask) {
const title = steps.trigger.event.properties.Task.title[0].plain_text;
const dueDate = steps.trigger.event.properties["google task date format"].formula.string;
const url = "https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks";
const body = {
title: title,
due: dueDate,
notes: notionPageUrl,
};
await axios(this, {
method: "POST",
url: url,
headers: {
Authorization: `Bearer ${steps.google_auth.$auth.oauth_access_token}`,
"Content-Type": "application/json",
},
data: body,
});
}
},
});
I apologize for the confusion earlier. It seems I made a mistake in my previous response. Since you’ve renamed the step to google_auth, you should access the oauth_access_token using the new step name. Please update the headers in your axios request like this: headers: { Authorization: `Bearer ${steps.google_auth.google.$auth.oauth_access_token}`, "Content-Type": "application/json", }, Here’s the updated code: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ async run({ steps }) { const notionPageUrl = steps.trigger.event.url; const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; const matchingTask = tasks.find(task => task.notes.includes(notionPageUrl)); if (!matchingTask) { const title = steps.trigger.event.properties.Task.title[0].plain_text; const dueDate = steps.trigger.event.properties[“google task date format”].formula.string; const url = “https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks”; const body = { title: title, due: dueDate, notes: notionPageUrl, }; await axios(this, { method: “POST”, url: url, headers: { Authorization: Bearer ${steps.google_auth.google.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: body, }); } }, });
I’m creating a step using the google tasks api prop. I want it to compare the content of my notion database to the content of my list_tasks step for google tasks. Where they don’t align, I would like for this step to create a google task that has the same title as the notion database page, the same due date as the due date property, and I would like for the notion URL to be written in the notes path of the google task. My trigger step has the paths for the title, the notion URL, and the due date, so I’d like for those to all be written as props in the code.
I understand that you want to create a Google Task when the content of your Notion database doesn’t match the content of your list_tasks step for Google Tasks. Based on the information you provided, I’ve created a Pipedream component that should help you achieve this: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google: { type: "app", app: "google", }, title: { type: "string", label: "Notion Page Title", }, notionUrl: { type: "string", label: "Notion Page URL", }, dueDate: { type: "string", label: "Due Date", }, }, async run({ steps }) { const notionPageUrl = this.notionUrl; const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; const matchingTask = tasks.find(task => task.notes.includes(notionPageUrl)); if (!matchingTask) { const title = this.title; const dueDate = this.dueDate; const url = "https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks"; const body = { title: title, due: dueDate, notes: notionPageUrl, }; await axios(this, { method: "POST", url: url, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: body, }); } }, }); This component takes the Notion page title, URL, and due date as props. It then checks if there’s a matching task in the list_tasks step data. If no matching task is found, it creates a new Google Task with the provided title, due date, and Notion URL in the notes. Please update the url variable in the code with the correct URL for your Google Tasks API endpoint. Also, make sure to connect your Google account using the google prop.
When I used the code you just gave me, this was what the log gave me:
export: debug - {
“status”: 403,
“statusText”: “Forbidden”,
“headers”: {
“www-authenticate”: “Bearer realm=\“https://accounts.google.com/\“, error=\“insufficient_scope\“, scope=\“https://www.googleapis.com/auth/tasks\“”,
“vary”: “Origin, X-Origin, Referer”,
“content-type”: “application/json; charset=UTF-8”,
“date”: “Tue, 19 Sep 2023 14:08:07 GMT”,
“server”: “ESF”,
“content-length”: “629”,
“x-xss-protection”: “0”,
“x-frame-options”: “SAMEORIGIN”,
“x-content-type-options”: “nosniff”,
“alt-svc”: “h3=\“:443\“; ma=2592000,h3-29=\“:443\“; ma=2592000”,
“connection”: “close”
},
“config”: {
“url”: “https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks”,
“method”: “post”,
“data”: “{\“title\“:\“another new task at 12:47 pm\“,\“due\“:\“2023-09-18T00:00:00+00:00\“,\“notes\“:\“https://www.notion.so/another-new-task-at-12-47-pm-86e7c3adff39407db24c9aa8d58e472e\“}”,
“headers”: {
“Accept”: “application/json, text/plain, /“,
“Content-Type”: “application/json”,
“Authorization”: “Bearer ya29.a0AfB_byDnbQuAR-Yjj1zU7Ypt0ti69czxu9GvXrfjcX9OE8GmkCIafnITPT1TQ3H3lxheodAoRTphAJQlvuPCuUtCzl30j2P7X8nyzyOLgfMu8UHyYI4F29AJmA_CC1ZShR2nsh1Qap2hL2XkuAfX1TroRLyO_oGfM7iFaCgYKAdYSARMSFQGOcNnCzSs2AR5bVLIoK6McdoT_Kg0171",
“User-Agent”: “axios/0.21.4",
“Content-Length”: 168
},
“transformRequest”: [
null
],
“transformResponse”: [
null
],
“timeout”: 0,
“xsrfCookieName”: “XSRF-TOKEN”,
“xsrfHeaderName”: “X-XSRF-TOKEN”,
“maxContentLength”: -1,
“maxBodyLength”: -1,
“transitional”: {
“silentJSONParsing”: true,
“forcedJSONParsing”: true,
“clarifyTimeoutError”: false
}
},
“data”: {
“error”: {
“code”: 403,
“message”: “Request had insufficient authentication scopes.“,
“errors”: [
{
“message”: “Insufficient Permission”,
“domain”: “global”,
“reason”: “insufficientPermissions”
}
],
“status”: “PERMISSION_DENIED”,
“details”: [
{
“@type”: “type.googleapis.com/google.rpc.ErrorInfo”,
“reason”: “ACCESS_TOKEN_SCOPE_INSUFFICIENT”,
“domain”: “googleapis.com”,
“metadata”: {
“method”: “google.apps.tasks.data.v1.TaskService.Insert”,
“service”: “tasks.googleapis.com”
}
}
]
}
}
}
I see that you’re getting a 403 Forbidden error with the message “Request had insufficient authentication scopes.” This error occurs when the access token you’re using doesn’t have the required scope to perform the requested operation. In this case, it seems like you need the https://www.googleapis.com/auth/tasks scope. To fix this issue, you’ll need to update your Google app’s OAuth scopes in Pipedream to include this scope. You can follow the instructions in the Google app documentation to update the scopes. After updating the scopes, you’ll need to re-authenticate your Google app in Pipedream to obtain a new access token with the required permissions. Then, you can try running the code again.
Instead of using google’s Oath Scope, can we use google tasks api scope? I’m pretty sure I have permission for that one.
The Google Tasks API scope is actually an OAuth scope. If you have permission for the Google Tasks API scope, you can update your Google app’s OAuth scopes in Pipedream to include the required scope, which is https://www.googleapis.com/auth/tasks. After updating the scopes, re-authenticate your Google app in Pipedream to obtain a new access token with the required permissions. Then, you can use the new access token to make requests to the Google Tasks API within your Pipedream component code.
Can you make this code into a code that uses google_tasks authentication instead of google?
import { axios } from “@pipedream/platform”;
export default defineComponent({
props: {
google: {
type: “app”,
app: “google”,
},
title: {
type: “string”,
label: “Notion Page Title”,
},
notionUrl: {
type: “string”,
label: “Notion Page URL”,
},
dueDate: {
type: “string”,
label: “Due Date”,
},
},
async run({ steps }) {
const notionPageUrl = this.notionUrl;
const tasksData = steps.list_tasks.data;
const tasks = tasksData && tasksData.tasks ? tasksData.tasks : [];
const matchingTask = tasks.find(task => task.notes.includes(notionPageUrl));
if (!matchingTask) {
const title = this.title;
const dueDate = this.dueDate;
const url = “https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks”;
const body = {
title: title,
due: dueDate,
notes: notionPageUrl,
};
await axios(this, {
method: “POST”,
url: url,
headers: {
Authorization: `Bearer ${this.google.$auth.oauth_access_token}`,
“Content-Type”: “application/json”,
},
data: body,
});
}
},
});
Sure, I can help you modify the code to use the google_tasks authentication instead of google. Here’s the updated code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google_tasks: { type: "app", app: "google_tasks", }, title: { type: "string", label: "Notion Page Title", }, notionUrl: { type: "string", label: "Notion Page URL", }, dueDate: { type: "string", label: "Due Date", }, }, async run({ steps }) { const notionPageUrl = this.notionUrl; const tasksData = steps.list_tasks.data; const tasks = tasksData && tasksData.tasks ? tasksData.tasks : []; const matchingTask = tasks.find(task => task.notes.includes(notionPageUrl)); if (!matchingTask) { const title = this.title; const dueDate = this.dueDate; const url = "https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks"; const body = { title: title, due: dueDate, notes: notionPageUrl, }; await axios(this, { method: "POST", url: url, headers: { Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: body, }); } }, }); In this updated code, I’ve replaced the google prop with google_tasks and updated the Authorization header to use this.google_tasks.$auth.oauth_access_token instead of this.google.$auth.oauth_access_token.
In this code, what prop are you using to see if the tasks match in google tasks and the notion database?
**import** { axios } **from** "@pipedream/platform";
export **default** defineComponent({
props: {
google_tasks: {
type: “app”,
app: “google_tasks”,
},
title: {
type: “string”,
label: “Notion Page Title”,
},
notionUrl: {
type: “string”,
label: “Notion Page URL”,
},
dueDate: {
type: “string”,
label: “Due Date”,
},
},
**async** run({ steps }) {
**const** notionPageUrl = **this**.notionUrl;
**const** tasksData = steps.list_tasks.data;
**const** tasks = tasksData && tasksData.tasks ? tasksData.tasks : [];
**const** matchingTask = tasks.find(task => task.notes.includes(notionPageUrl));
`**if** (!matchingTask) {`
`**const** title = **this**.title;`
`**const** dueDate = **this**.dueDate;`
`**const** url = "https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks";`
`**const** body = {`
title: title,
due: dueDate,
notes: notionPageUrl,
};
`**await** axios(**this**, {`
method: “POST”,
url: url,
headers: {
Authorization: `Bearer ${`**this**.google_tasks.$auth.oauth_access_token}`,`
“Content-Type”: “application/json”,
},
data: body,
});
}
},
});