I’m having the same problem exactly and just noticed this line in the script:
credential.authorize()
Followed by ‘var secret =…’ and ‘var inbox…’ commands.
I’m not a programmer, but I’m wondering if the line I referenced above is waiting for a variable of some sort.
I too have generated a secret from integrations and have add the page id.
What happens if you put that back? The first script step looks to be setting up credentials, but otherwise it just defines a set of functions. That second script step looks like it is calling the functions to do the work.
I wonder if the “Test Script” comment might refer to the commented out line that comes after, or if it is more an example script than a test script.
Note:I am not a Notion user, so I can’t check it actually running.
Good thinking there, but I just deleted the action and the credentials stored in preferences and readded the action and the page ID and secret and got the same behavior. The action runs successfully, but I don’t see any content on the page where I took the ID.
Hi @moggy1972, can you also add version to functions other than addDatabasePage()? such as addPage() and addTextBlock()? They are failing without the version line. Thanks!
Thanks a lot @moggy1972 for this. It’s going to be an everyday run action from my drafts.
However, I could be perfect if I could add them to a database. Is it possible to implement that function?
Thanks!
Yes - it’s definitely possible. The add database call in the API is slightly different. The parent id goes in a field called “database_id”, rather than “page_id”. And the structure of the date is a little different.
For a non-database page, the body of the request just needs to be:
body = { “parent”: { “page_id”: YOUR_PAGE_ID },“properties”: {“title”: [{“text”: {“content”: YOUR_TITLE}}]}}
For a database page, it’s a little longer:
body = { “parent”: { “database_id”: YOUR_DATABASE_ID },“properties”: {“Name”: {“title”: [{“text”: {“content”: YOUR_TITLE}}]}}}
There has been a new release of the API with some additional functions so I’m planning on updating the actions over the next week or so, but there should be enough information here for you to be able to do it yourself for now.
Thanks for the action.
I screwed up the initial setup but after reading the posts I got it to function.
But like other people the action seems happy but no data is transferred to Notion.
I have deleted the app and reinstalled but the initial setup questions never appear.
where can I delete it totally and start from scratch?
Appreciate your work, thanks
Pete
There’s two things I can think might be happening here.
Your credentials are held within Drafts in Settings. I’m not sure if they persist after you delete Drafts, but you can tell Drafts to forget specific credentials through Settings/Credentials. If you select “forget” for the Notion credential, you should be prompted to add the secret next time you run the action.
Within Notion, you need to set up an integration to use pages within databases or top-level pages. This is where you would get the secret key from. If you want to use a different area within your Notion workspace, you need to go to the database main page and use Share (top right) to share it with your integration.
Hi @moggy1972 - I have been having such a hair-brained time trying to settle on ONE Productivity/Canvas/Note ecosystem and your “Add to Notion” action might make that decision for me but I’m having trouble getting your “add to Notion” action to fire correctly.
I have recreated my Notion integration, deleted the credentials in Drafts and entered the Secret/Page ID in the dialog box but I immediately get the:
It’s on my todo list to tidy this all up - it’s not as clear as it should be! [I see it’s working for you now, but sharing in case this is helpful for others]
What I meant by hardcoding was that instead of using credentials, you could just have:
secret = "myintegrationsecret"
inbox = "pageid"
Where “secret” is the code that was created when you set up the integration with Notion. (find it in “Settings & Members/Integrations”) And “pageid” is the uuid of the page you want to add to.
It’s probably relatively low risk to hard code the “secret” - I just didn’t want it being shared when I shared my action.
The add to database action would be very similar - you just need to tweak the body of the javascript request to something like:
I should PROBABLY just be leaving well enough. I’ve killed the error I was getting about not being able to find the variable DATABASE_ID (capitalization) and adding to a page is still good but my test database isn’t being updated. I feel like there should be more in “Example 2” than what I have below:
// Example 2: Add item to database in Notion with the draft title as Action. // Need to add the database ID
I think I’ve created enough functionality for my setup using the “Add to Notion” and a synced block on my Inbox page. So when a quick note from Drafts comes in I can drag it up to a record in my synced database.
I don’t use Notion, but I have had a quick scan through the code. The line that is failing looks to be line 14 in the second script step - second line below.
I tried pasting the page.id into the second script but that didn´t work. Is there a problem the code not being indented after I paste the page.id ? I tried pressing tab to make it indent but it didn´t work.
I get the impression from the results that you are changing it about without understanding it and then just hoping it works.
I see one code in there from one run which is a page not found. So that’s potentially fundamental for an API call, assuming that’s what triggered it.
If you start again from the beginning with the original action and configure it as originally done, we can start from there and check if it works, config, error messages, etc. Otherwise, we’re dealing with a mystery target that you keep also moving!
Briefly reviewing the script, the page.id error you are getting is consistent with what I would expect if the call the addPage in the previous line fails. The action itself wasn’t written with any error handling/report, you’d have to backtrack to add some debugging code in the addPage method to sort out what might be going wrong.
Note that the Notion API is in beta and has been changing a lot, so it would not surprise me if this example just needs some updates for changes made at their end. Using beta APIs is not for the squeamish.
I hope to add more direct support for Notion in Drafts once their API settles down and comes out of beta.
Okay, so the 404 error for page creation as being logged in the custom addPage() function would relate to the create a page API call. The API documentation for this lists the following for the 404 return code.