Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Connecting apps

Let a customer connect their apps with a setup link or the embedded widget, then read the connections they made.

Before fastn can read or write a customer's data in an app, the customer has to connect that app (sign in to it). There are two ways:

Way
What the customer sees
SDK

Setup link

A hosted fastn page you send them a link to.

customer.connect("hubspot"), or customer.setupLink(...) with a widget id

Embedded widget

The fastn widget inside your own app.

customer.embedToken(...), then the widget package in the browser

Either way, the result is a connection: one connected account, with its own connectionId.


Widgets

A widget decides which app (or apps) a setup link or the embedded widget offers. You build widgets in the dashboard: see Widgets. From the SDK you only read them, to get their ids.

const widgets = await fastn.embed.listWidgets();
for (const w of (widgets.data ?? []) as any[]) {
  console.log(w.id, w.name, (w.connectorRefs ?? []).map((c: any) => c.slug));
}
Do this
SDK
Answer

List your widgets

fastn.embed.listWidgets()

{ data: [ { id, name, slug, connectorRefs, unifiedRefs, enabled, status, … } ] }. connectorRefs[].slug is the app, for example hubspot.

Read one

fastn.embed.getWidget({ id: "wgt_…" })

{ data: widget }


Connect by app

The short way to a setup link names the app and nothing else. The SDK finds your widget for that app, creates the link for the customer and answers the address to send:

const link = await customer.connect("googleCalendar", {
  expiresInMinutes: 60 * 24,
  redirectUrl: "https://app.example.com/connected",
  metadata: { flowId: "flow_123" },
});

console.log(link.url);     // send this to the customer
Field
Required
Meaning

app (first argument)

Yes

The app's slug, for example googleCalendar or hubspot.

widgetId

No

Which widget, when more than one of your widgets offers the app (409 WIDGET_AMBIGUOUS otherwise). No widget offers it: 404 WIDGET_NOT_FOUND.

connectionName, label, expiresInMinutes, redirectUrl, metadata, allowAdditionalConnection

No

As on setupLink below. connectionName defaults to the widget's name.

Answer: { setupId, url, status, expiresAt, widgetId }. Read or cancel the link later with customer.links.get(setupId) and customer.links.cancel(setupId). The widget list is reused for 60 seconds, so a widget you create after start-up is found without a restart.


A setup link is a one-time link to a hosted fastn page. The customer opens it, signs in to the app, and the connection is stored on that customer. connect(app) above makes one by app name; setupLink takes the widget id yourself:

Input

Field
Required
Meaning

widgetId

Yes

Which widget, and so which app, the link connects.

connectionName

Yes

The name of the new connection, for example Front desk calendar. It is shown to the customer and comes back on the connection.

label

No

A label for the link, for example the customer's name.

expiresInMinutes

No

How long the link works, in minutes. Your org config carries a default link lifetime (setupLinkDefaultTtlMinutes, below).

redirectUrl

No

Where the browser goes when setup ends. It must be on your list of registered redirect addresses (below), or the call is refused.

metadata

No

Your own data, any JSON object. fastn does not use it. It comes back to you on the link and on the link's events, so you can tell which of your flows the new connection is for.

allowAdditionalConnection

No

true lets the customer add another account for the same app (for example a second calendar). The answer includes it only when it is true.

The SDK fills in the customer for you. If the customer does not exist yet, the link creates it.

Answer

Field
Meaning

setupUrl

The link to send to the customer. It carries a live credential: do not log it or share it beyond the customer.

setupId

The link's id, to check or cancel it.

status

pending (new), complete (used) or revoked (cancelled).

expiresAt

When the link stops working.

orgId

Your customer id. The link belongs to the customer you created it for.

Do this
SDK
Answer

Read a link

fastn.embed.getSetupLink({ id: "stp_…" })

{ data: { setupId, status, widgetId, orgId, label, connectionName, installationId, expiresAt, redirectUrl, allowAdditionalConnection, metadata, widget } }. installationId is set once the link is complete.

Cancel a link

fastn.embed.cancelSetupLink({ id: "stp_…" })

{ data: { setupId, status: "revoked" } }

To hear when a link is used or expires, subscribe to the setup_link.completed and setup_link.expired events.

Redirect addresses

redirectUrl must be registered on your org first. Read the list from your org config:

To change it, send the full list with fastn.orgs.updateOrgConfig({ id, setupLinkRedirectUrls: [ … ] }). Saving the list replaces it, so include every address you still use.

A setup link with an address that is not on the list is refused with 400 and the code SETUP_LINK_REDIRECT_NOT_ALLOWED.


Embedded widget: embed tokens

To show the fastn widget inside your own app instead of sending a link, your backend creates a short-lived token for the customer and hands it to the page.

Field
Required
Meaning

userId

No

Your own id for the person using the widget. Leave it out and fastn makes one.

userEmail, userName

No

The person's email and name.

metadata

No

Your own data.

Answer:

orgId is your customer id. The token is for the customer you created it for.

expiresIn is in seconds: the token lasts eight hours. Treat the token as a credential. How the browser side uses it is in Embedding the widget and Token API.


Connections

When the customer connects an app, fastn stores a connection on that customer. You receive its id on the connection.connected event, and you can list connections at any time.

A connection

Field
Meaning

id

The connectionId. Pass it to unified records when a customer has more than one account for the same app.

name

The connection's name, for example the connectionName from the setup link.

connector.slug

The app, for example hubspot. Use it as provider in unified calls and as connector in direct actions.

connectorId

The app's id in the catalog.

status

For example ACTIVE or EXPIRED. An expired connection needs the customer to sign in again.

isDefault

The account used when you do not pick one.

orgId, orgName

The customer the connection belongs to: your customer id and its name.

Other connection calls

Do this
SDK
Input

List a customer's connections

customer.connections()

Optional: includePartnerPool: "true" adds your own org's shared connections that the customer can also use.

Read one

fastn.connections.getConnection({ id })

id (required): the connectionId. Answer: { data: connection }. Credentials are not returned.

Rename

customer.renameAccount(connectionId, name)

The connection must belong to this customer (404 CONNECTION_NOT_FOUND otherwise), so one key serving every customer can never touch another customer's account by mistake.

Disconnect

customer.disconnect(connectionId)

Same check. The account is removed; stop using its connectionId.

A unified call for a customer can also use connections in your own org's shared pool. So providers() (see Unified records) can show an app as connected even when customer.connections() does not list it. Use customer.connections({ includePartnerPool: "true" }) to see both.

See also Connections for connection statuses in the dashboard.

Last updated

Was this helpful?