Notion Scripting to multiple workspaces HELP!

I found an excellent draft action on the directory which using the notion scripting option to add a new page to a database. I have multiple workspaces in notion and I have been able to configure the normal notion actions, using the credentials identifier, to be able to add into different workspaces but I am unable to get the script option to work across multiple workspaces. I have one that works in one space but I tried to copy it and change the database id to another workspace and I was unable to get it work. I no it must be something to do with authentication but cannot seem to figure it out.

Here is script:

// Notion Add Page to Databse + MD 
// adds page to notion db with MD converted to Notion block types
// Updated 22/3/22 - change to block properties
// Assumes that the title property of your db pages default is "Name", if not, change below
// Enter your database ID below

/* ----- database id: paste ID between "quotes" -----*/
const dbid = "**I INSERTED MY DATABASE ID HERE AS INSTRUCTED**"; // from db page link, between last "/" and "?"

// endpoint url
const endpoint = "";

//get draft title + content, remove blank lines
const lines = draft.content.replace(/$\s*\n+/gm, "\n").trim().split('\n'); 

const title = lines.shift().replace(/^# /, "");

// create page
const parent = { "database_id": dbid };

//"Name" refers to the title property of your db pages, default is "Name", if you have changed this, replace "Name" below
const properties = { 
					"Name": { "title": [ {"text": { "content": title}}]} ,				

const children = [];

const page = { parent, properties, children };	 


function addBlock(line){

	const block =	{"object": "block", "type" : "paragraph"};
	const anyPref = /^(\s*([-*+]|#+)\s+)/;

	// map prefix to block type
	const types = new Map ([  
					["to_do", /^(\s*[-*+]\s\[\s]\s+)/],
					["bulleted_list_item", /^(\s*[-*+]\s+)/],
					["heading_3", /^(\s*###\s+)/],	
					["heading_2", /^(\s*##\s+)/],
					["heading_1", /^(\s*#\s+)/],  

	// if any prefix
	if (anyPref.test(line)) {

		// get type
		types.forEach( ( reg, name ) => {
						if (reg.test(line)) {
							block.type = name;
							line = line.replace(reg, ""); 
	// complete block
	block[block.type] = {"rich_text": [{ "type": "text", 
									"text": { "content" : line }}]};


// ---------------------

//if lines, add child blocks
if (lines) {


// create Notion instance to make request
let notion = Notion.create();
let response = notion.request({
	"url": endpoint,
	"method": "POST",
	"data": page 

// result 
if (!response.statusCode == 200) {

	alert(`Notion Error: ${response.statusCode}

The way to use credentials with script objects that work with services like Notion, is to pass the credential identifier into the constructor for the service object. The change you would need to make is:

// replace this line...
let notion = Notion.create();
// with this line...
let notion = Notion.create("MY-CREDENTIAL-ID");

(related reference docs)

Oh my goodness, thank you so much; it worked straight away. Honestly, thank you for making such an amazing app! I use it everyday and being able to dot down text and send it anywhere is amazing!

1 Like