Skip to content

Notion OAuth

JsWorkflows provides a platform-managed Notion OAuth app — you do not need to create a Notion integration or provide credentials.

Notion OAuth grants access to the pages and databases you explicitly share with the integration during the authorisation flow. There are no scope selections — access is controlled at the workspace level by what you choose to share.

  1. Go to OAuth Connections → Add Connection → Notion.
  2. Sign in with your Notion account.
  3. Select the pages and databases you want to give JsWorkflows access to.
  4. Click Allow access.
  5. Give the connection a handle (e.g., my-notion).

Notion tokens do not expire and are not automatically refreshed.

class Workflow {
async start(data, headers, api) {
const { token, error } = await api.getOAuthToken('my-notion');
if (error) { api.log('OAuth error:', error); return; }
await api.scheduleNextStep({
delay: 10,
action: 'createRecord',
payload: {
token,
orderId: data.name,
total: data.total_price,
currency: data.currency,
},
});
}
async createRecord({ token, orderId, total, currency }, headers, api) {
await fetch('https://api.notion.com/v1/pages', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
'Notion-Version': '2022-06-28',
},
body: JSON.stringify({
parent: { database_id: env.NOTION_DATABASE_ID },
properties: {
Name: { title: [{ text: { content: orderId } }] },
Total: { number: parseFloat(total) },
Currency: { rich_text: [{ text: { content: currency } }] },
},
}),
});
}
}
const { token } = await api.getOAuthToken('my-notion');
const resp = await fetch(`https://api.notion.com/v1/databases/${env.NOTION_DATABASE_ID}/query`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
'Notion-Version': '2022-06-28',
},
body: JSON.stringify({}),
});
const { results } = await resp.json();