> ## Documentation Index
> Fetch the complete documentation index at: https://docs.argyle.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Callbacks

> Learn how to configure callbacks in Link.

Callbacks are used in Link when a user performs one action that triggers another action.

## Overview

When Argyle Link is initialized for a new user (in other words, `userToken` was not specified), a new user is created just before the user tries to connect their first payroll account. This is when the `onUserCreated` callback is invoked with an object containing a `userId` and a `userToken`.

Whenever a user creates a new account on Link, the `onAccountCreated` callback is invoked with the `accountId` and `userId` parameters.

* Store those IDs on your database and use them to retrieve the user's employment data from the Argyle API.
* Save the user ID on your database to be able to reference the user's [accounts](/legacy/api-reference/accounts) and [request their user tokens](/legacy/api-reference/users#create-token) from the API.

The `onAccountUpdated` callback is invoked when a user updates their credentials for an existing account.

## Callbacks reference

| Attribute                   | Type                                           | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| --------------------------- | ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `onPayDistributionSuccess`  | function *optional*                            | A callback function invoked after a successful pay distribution update flow. This callback function provides `accountId`, `userId`, and `linkItemId`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `onPayDistributionError`    | function *optional*                            | A callback function invoked after an error occurs during the pay distribution update flow. This callback function provides `accountId`, `userId`, and `linkItemId`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `onCantFindLinkItemClicked` | function *optional*                            | An optional callback that is triggered when the user selects the **Can't find your income source?** button in Argyle Link. When this callback is triggered, Link closes and the callback function receives the user's search query. To enable this user flow, you must define the `onCantFindLinkItemClicked` callback in your implementation and also select the corresponding **Callback** experience type in [Flows](https://console.argyle.com/flows).                                                                                                                                                                                                                                                                                                                                                                          |
| `onAccountCreated`          | function *optional*                            | A callback function invoked immediately after a user clicks *connect* and a new account is created. The callback will be invoked before authenticating the account with the Link item. This callback function provides `accountId`, `userId`, and `linkItemId`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `onAccountConnected`        | function *optional*                            | A callback function invoked every time a new account is successfully authenticated with a Link item, including any multi-factor authentication requests. If your `linkItems` list contains only one Link item, it is safe to close Argyle Link at this point. This callback function provides `accountId`, `userId`, and `linkItemId`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `onAccountUpdated`          | function *optional*                            | A callback function invoked when a user updates their account credentials. This callback function provides `accountId`, `userId`, and `linkItemId`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `onAccountRemoved`          | function *optional*                            | A callback function invoked when a user removes an account. This callback function provides `accountId`, `userId`, and `linkItemId`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `onUserCreated`             | function *optional*                            | A callback function invoked when a new user is created. This callback function provides `userId` and `userToken`. The [user object](/legacy/api-reference/users#user-object) is created on the first attempt of a new user to connect an account.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `onError`                   | function *optional*                            | A callback function invoked when Link encounters an internal problem that breaks the flow for the user. This callback function provides the type of the error that occurred. Possible values: `INVALID_LINK_ITEMS`, `INVALID_PD_CONFIG`, `INVALID_LINK_KEY`, `INVALID_USER_TOKEN`, `GENERIC` For more details and troubleshooting, see [Link Errors](/legacy/guides/troubleshooting/link-errors).                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `onAccountError`            | function *optional*                            | A callback function invoked every time an account fails to authenticate with a Link item. This callback function provides `accountId`, `userId`, and `linkItemId`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `onClose`                   | function *optional*                            | A callback function invoked immediately after the user closes Link.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `onTokenExpired`            | function *optional*                            | A callback function invoked when the `userToken` expires. This callback function provides another function as a parameter, which you should call with your new `userToken` as an argument. We recommend generating a new `userToken` every time Link is initialized for a user.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `onUIEvent`                 | function *optional*                            | The `onUIEvent` callback is invoked when specific UI events are activated on Link. These event callbacks provide a data object that contains `linkItemId`, `accountId`, `userID`, and `deepLink`. The events include: - The user reaches the Success screen after selecting and successfully submitting the **Can't find your income source?** form. - The user reaches the Success screen after successfully uploading documents. - The user deleted documents. - The user opened the Document Status screen after they have already uploaded documents.- The user opened the Form Status screen after they have already submitted a form. Also, some events have specific properties. Refer to [Link Analytics](/legacy/guides/argyle-link/analyze) to see all event-specific properties and the screen where they are activated. |
| `onExitIntroClicked`        | function *optional* *(conditionally required)* | This callback is associated to the secondary button on the Intro screen. Upon receiving this event, you can initiate a backup flow for your users.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `onFormSubmitted`           | function *optional*                            | This callback is invoked when a user submits a form. This callback function provides `accountId` and `userId`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `onDocumentsSubmitted`      | function *optional*                            | This callback is invoked when a user completes the document upload flow. This callback function provides `accountId` and `userId`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
