Skip to content

JsWorkflows provides a platform-managed Microsoft OAuth app. You do not need to register an Azure application or provide credentials.

ResourceOperationScope
Outlook MailRead mailMail.Read
Outlook MailSend mailMail.Send
Outlook MailRead & write mailMail.ReadWrite, Mail.Send
OneDriveRead filesFiles.Read
OneDriveRead & write filesFiles.ReadWrite
Outlook CalendarRead calendarCalendars.Read
Outlook CalendarRead & write calendarCalendars.ReadWrite
Outlook ContactsRead contactsContacts.Read
Outlook ContactsRead & write contactsContacts.ReadWrite
User ProfileRead profileUser.Read
  1. Go to OAuth Connections → Add Connection → Microsoft.
  2. Select the resources and operations your workflow needs.
  3. Sign in with your Microsoft account and grant the requested permissions.
  4. Give the connection a handle (e.g., my-microsoft).

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

Access tokens are refreshed automatically when they expire.

export class Workflow {
async start(data, _headers, api) {
const { token, error } = await api.getOAuthToken('my-microsoft');
if (error || !token) throw new Error(error || 'Missing Microsoft token');
const response = await fetch('https://graph.microsoft.com/v1.0/me/sendMail', {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
message: {
subject: `Order ${data.name} confirmed`,
body: { contentType: 'Text', content: `Thank you for your order of ${data.total_price} ${data.currency}.` },
toRecipients: [{ emailAddress: { address: data.email } }],
},
saveToSentItems: false,
}),
});
if (!response.ok) {
throw new Error(`Microsoft Graph ${response.status}: ${await response.text()}`);
}
}
}

sendMail returns 202 Accepted with no response body on success.

const { token, error } = await api.getOAuthToken('my-microsoft');
if (error || !token) throw new Error(error || 'Missing Microsoft token');
const csvString = 'order,amount\\n1001,49.95\\n';
const fileBytes = new TextEncoder().encode(csvString);
const response = await fetch('https://graph.microsoft.com/v1.0/me/drive/root:/reports/orders.csv:/content', {
method: 'PUT',
headers: {
'Content-Type': 'text/csv; charset=utf-8',
Authorization: `Bearer ${token}`,
},
body: fileBytes,
});
if (!response.ok) {
throw new Error(`Microsoft Graph ${response.status}: ${await response.text()}`);
}
const driveItem = await response.json();
console.log(`Uploaded ${driveItem.name} (${driveItem.size} bytes)`);