fastify-xplaid
link.createToken(params)
Create a Plaid Link token for initializing the Plaid Link UI.
link.createToken(params)
Creates a short-lived Link token used to initialize the Plaid Link UI in your frontend. In update mode, pass an existing accessToken to allow a user to re-authenticate or add products to an Item.
Signature
fastify.xplaid.link.createToken(params: {
userId: string
clientName?: string
products?: string[]
countryCodes?: string[]
language?: string
webhook?: string
redirectUri?: string
accessToken?: string
}): Promise<{ linkToken: string; expiration: string; requestId: string }>
Params
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
userId | string | Yes | — | Unique client user ID (your internal user ID) |
clientName | string | No | "App" | Application name shown in Link UI (max 30 chars) |
products | string[] | No | ["transactions"] | Plaid products to enable (ignored when accessToken is set) |
countryCodes | string[] | No | ["US"] | Country codes for institution filtering |
language | string | No | "en" | Display language |
webhook | string | No | — | Webhook URL for real-time item updates |
redirectUri | string | No | — | OAuth redirect URI |
accessToken | string | No | — | Existing access token for update mode |
Returns
{ linkToken: string; expiration: string; requestId: string }
Throws
Error: [xPlaid] userId is required and must be a non-empty string—userIdmissing or empty- Plaid API error with
.plaidErrorand.statusCode
Examples
New connection
fastify.get("/plaid/create-link-token", async (request) => {
const { linkToken } = await fastify.xplaid.link.createToken({
userId: request.user.id,
clientName: "My Finance App",
products: ["transactions", "auth"],
countryCodes: ["US"],
webhook: "https://myapp.com/webhooks/plaid",
});
return { linkToken };
});
Update mode — re-authenticate existing item
fastify.get("/plaid/update-link-token", async (request) => {
const item = await db.plaidItem.findUnique({ where: { userId: request.user.id } });
const { linkToken } = await fastify.xplaid.link.createToken({
userId: request.user.id,
accessToken: item.accessToken, // triggers update mode
});
return { linkToken };
});
See also
- link.exchangePublicToken(publicToken) — next step after user completes Link
- link.getToken(linkToken) — inspect a link token's metadata
AI Context
package: "@xenterprises/fastify-xplaid"
method: fastify.xplaid.link.createToken(params)
use-when: Create a Plaid Link token to initialize Plaid Link in the browser — first step of the bank connection flow
params: userId (required), clientName, products, countryCodes, webhook, language, accessToken (update mode)
returns: { linkToken, expiration, requestId }
