Notion OAuth
JsWorkflows provides a platform-managed Notion OAuth app — you do not need to create a Notion integration or provide credentials.
Available scopes
Section titled “Available scopes”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.
Connecting
Section titled “Connecting”- Go to OAuth Connections → Add Connection → Notion.
- Sign in with your Notion account.
- Select the pages and databases you want to give JsWorkflows access to.
- Click Allow access.
- Give the connection a handle (e.g.,
my-notion).
Notion tokens do not expire and are not automatically refreshed.
Example — create a page in a database
Section titled “Example — create a page in a database”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 } }] }, }, }), }); }}Example — query a database
Section titled “Example — query a database”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();