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

# Initialize

[@qonto/embed-sdk](../README) / initialize

# Variable: initialize()

> **initialize**: (`initializeParams`) => `void`

Initializes the SDK with the provided parameters. Calling this function is
not mandatory, but in stateful environments like in a single page application
running in a browser, it is recommended. The `initialize` function is useful
to pass data to the SDK that otherwise would have to be passed in every
function call.
In order to call functions afterward without having to pass repetitive
parameters to them, it is helpful to call this function before using any
other SDK functions. In client side environments, it expects at least the
`operationSettings.proxyEndpointDescriptor` param, while in server side
environments it expects at least an `accessToken`.
It's also useful to rely on the exposed SDK constants to pass some of the
parameters.

## Parameters

### initializeParams

[`InitializeParams`](../-internal-/interfaces/InitializeParams)

An object with the parameters to initialize the SDK.
The only required parameter is the `proxyEndpointDescriptor` in client
environments or `accessToken` in server environments.

* `accessToken`: The access token to authenticate the user. This has to be
  previously generated using the OAuth authentication flow. Only needed in
  server side usage, and not recommended in client side.
* `environment`: Optional parameter to set the SDK's environment. If not provided,
  the SDK will default to `ENVIRONMENTS.PRODUCTION`. Use `ENVIRONMENTS.STAGING` to set
  the SDK to staging.
* `branch`: Optional parameter to set the SDK's branch. This is only relevant when the
  `environment` is set to `ENVIRONMENTS.STAGING`. The possible values are `BRANCHES.MASTER`,
  `BRANCHES.SANDBOX` and `BRANCHES.QA`. If not provided, the SDK will default to
  `BRANCHES.MASTER`.
* `operationSettings`: Optional settings to configure the SDK's operations that will
  be performed after the initialization. This can be also provided when calling the
  operation functions themselves.
* `uiParentElementId`: The id of the DOM element where the SDK will render UI
  in those functions that involve rendering UI in the caller website. Normally,
  it will make more sense to add this param when calling functions that require
  rendering UI, because each function call will likely render the UI under a
  different parent.
* `mfaPreference`: The MFA preference to use for the operations. This can be either
  `MFA_METHODS.PASSKEY`, `MFA_METHODS.PAIRED_DEVICE` or `MFA_METHODS.SMS_OTP`. If not
  provided, the SDK will default to `MFA_METHODS.PASSKEY`.
* `locale`: Optional 2 digit language code to set the language in which the UI elements
  injected by the SDK will show the text.

## Returns

`void`

## Throws

`InvalidParametersError` If the access token is not provided or the specified
parameters don't comply with the expected format.

## Examples

```ts theme={null}
// The simplest way to initialize the SDK is to provide an access token.
import { initialize } from '@qonto/embed-sdk/common';

const initializeParams = {
  accessToken: 'an-access-token',
};

initialize(initializeParams);
```

```ts theme={null}
// Initializes the SDK to work in the staging environment, concretely in the sandbox branch. Also, it sets the
//  ID of the DOM element where the SDK will render the multi-factor authentication (MFA) UI if a sensitive
//  operation is requested after SDK initialization.
import { initialize, constants } from '@qonto/embed-sdk/common';

const initializeParams = {
  accessToken: 'an-access-token',
  environment: constants.ENVIRONMENTS.STAGING,
  operationSettings: {
    uiParentElementId: 'mfa-container',
  },
};
initialize(initializeParams);
```
