Skip to content

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 authorization flow. There are no scope selections. Access is controlled 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).

Use lowercase letters, numbers, and hyphens only for the handle.

Notion tokens do not expire and are not automatically refreshed.

export class Workflow {
async start(data, _headers, api) {
await api.scheduleNextStep({
delay: 10,
action: 'createRecord',
payload: {
orderId: data.name,
total: data.total_price,
currency: data.currency,
},
});
}
async createRecord({ orderId, total, currency }, _headers, api) {
const { token, error } = await api.getOAuthToken('my-notion');
if (error || !token) throw new Error(error || 'Missing Notion token');
const response = await fetch('https://api.notion.com/v1/pages', {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json; charset=utf-8',
'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 } }] },
},
}),
});
if (!response.ok) {
throw new Error(`Notion API ${response.status}: ${await response.text()}`);
}
const page = await response.json();
console.log(`Created page ${page.id}`);
}
}

The property names and types in properties must match the target database schema. For example, Name must be a title property, Total a number property, and Currency a rich text property in that database.

const { token, error } = await api.getOAuthToken('my-notion');
if (error || !token) throw new Error(error || 'Missing Notion token');
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; charset=utf-8',
'Notion-Version': '2022-06-28',
},
body: JSON.stringify({}),
});
if (!resp.ok) {
throw new Error(`Notion API ${resp.status}: ${await resp.text()}`);
}
const { results } = await resp.json();