This topic was automatically generated from Slack. You can find the original thread here.
Struggling to get my connection working. I used to use a custom integration but moved to the default Notion / Pipedream connection. The default connection “template” is below. I’m unable to determine how to use the notion object in functions outside defineComponent. I tried moving all my functions within defineComponent but and having run() call main but that does not work. I think the layout below is proper but I do not know the syntax or I’m missing an import statement, etc.
Thanks,
-Rich
Hi Richard, you’d have to keep the code inside the defaultComponent export. You can put it inside the run function or add methods to reuse methods (see docs). Could you share your use case for writing custom code using the template and not the available registry components?
I’m working on migrating to that but not finding easy ways post querying a database to loop and create multiple pages based on the query results.
But thank you for the advice above. “this.notion” now working however, this.main() called from the run() method is throwing an exception that main is not a function. When I moved main into define component I had to drop async function main() to just main. Now when I call using this.main(); from within run() to kick off the process I receive the errors. Thoughts?
Thanks! I’m much closer now. Will the following ensure the notion object exists prior to calling this.handlerRecurringTasks()? Right now that function calls this.notion.databases.query and it appears it’s not defined. Anything else I should be doing? async run({ steps, $ }) { await axios($, { url: https://api.notion.com/v1/users/me`,` headers: { Authorization: Bearer ${this.notion.$auth.oauth_access_token}, "Notion-Version": 2022-06-28, }, }) await this.handleRecurringTasks(); },
The notion object that is being exposed to you there is the Notion authentication app prop, and not exactly the notion sdk library. Check out lesson 1.4 from Pipedream University to understand what is this app prop and how you can use it
You can leverage Pipedream’s authentication handling by accessing the oauth_access_token and inject it to the Notion SDK client just like we do here. With this client, you can then access the objects and functions from the official Notion API
The link above is for our components repository where we store the source code for our registry components. You can see the code for our Notion components in this link.
Added a method for _getNotionClient(). Now calling the “notion object” using: const response = await this._getNotionClient().databases.query({…}).
Last run I received this error: pnpm install --prefer-offline --ignore-scripts -P and it looks like I’m trying to install something but it failed.
Error: Command failed: pnpm install --prefer-offline --ignore-scripts -P
at __node_internal_genericNodeError (node:internal/errors:865:15)
at ChildProcess.exithandler (node:child_process:422:12)
at ChildProcess.emit (node:events:517:28)
at maybeClose (node:internal/child_process:1098:16)
at ChildProcess._handle.onexit (node:internal/child_process:303:5)