X Enterprises
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

NameTypeRequiredDefaultDescription
userIdstringYesUnique client user ID (your internal user ID)
clientNamestringNo"App"Application name shown in Link UI (max 30 chars)
productsstring[]No["transactions"]Plaid products to enable (ignored when accessToken is set)
countryCodesstring[]No["US"]Country codes for institution filtering
languagestringNo"en"Display language
webhookstringNoWebhook URL for real-time item updates
redirectUristringNoOAuth redirect URI
accessTokenstringNoExisting access token for update mode

Returns

{ linkToken: string; expiration: string; requestId: string }

Throws

  • Error: [xPlaid] userId is required and must be a non-empty stringuserId missing or empty
  • Plaid API error with .plaidError and .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

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 }
Copyright © 2026