# HTML + Javascript

## 1. Installation

To install the Preventor Broker SDK, add the following script.

```html
<script
    type="module"
    src="https://sdk.preventor.com/pvtidaas/broker/broker.esm.js"
></script>
```

## 2. Setup the SDK

1. Add `pvt-broker` tag into your HTML.

<pre class="language-html"><code class="lang-html"><strong>&#x3C;pvt-broker>&#x3C;/pvt-broker>
</strong></code></pre>

2. Set your configuration

You can find your credentials on the [Preventor platform](https://sandbox.preventor.com/)

<div align="left"><figure><img src="/files/j7ksSIe60LU5Dh9CXRFt" alt="" width="303"><figcaption><p>Go to settings / integration keys</p></figcaption></figure></div>

<div align="left"><figure><img src="/files/yTB9gr2S7jnut2x8dZxs" alt="" width="375"><figcaption><p>Integration keys</p></figcaption></figure></div>

You can find the broker ID on the [Preventor platform](https://sandbox.preventor.com/)

<div align="left"><figure><img src="/files/l3bSrEimlfRL4Z74jddo" alt="" width="169"><figcaption><p>Go to apps option</p></figcaption></figure></div>

<div align="left"><figure><img src="/files/ZF1DkQsCFbyb10aVAJ2F" alt="" width="316"><figcaption><p>Go to broker management</p></figcaption></figure></div>

<div align="left"><figure><img src="/files/qQhvt698DeXuxtVyozny" alt=""><figcaption><p>You must pass this Broker ID to your configuration. If don't have any broker, you can create it.</p></figcaption></figure></div>

```javascript
window.PvtBrokerSDK = {
    brokerId: 'YOUR_BROKER_ID',
    credentials: {
      apiKey: 'YOUR_API_KEY',
      clientSecret: 'YOUR_CLIENT_SECRET',
      tenant: 'YOUR_TENANT',
      banknu: 'YOUR_BANKNU',
      env: 'YOUR_ENV',
    },
  };
```

3. Call the `open()` method to open the component

```javascript
const component = document.querySelector('pvt-broker');
component.open();
```

4. `pvt-broker` emits a loaded event when the Preventer Broker SDK finishes downloading. In the example below, the loaded event is utilized to enable a button that opens the Preventer Broker SDK.

```javascript
const component = document.querySelector('pvt-broker');
const button = document.querySelector('button');  
button.addEventListener('click', () => component.open())

component.addEventListener('loaded', () => {
  button.disabled = false;
});
```

5. A complete `HTML`file should look similar to the example below.

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8" />
    <title>Preventor, Remote digital identity platform for brokers</title>
  </head>

  <body>
    <button disabled>Click me</button>
    <pvt-broker></pvt-broker>

    <script
      type="module"
      src="https://sdk.preventor.com/pvtidaas/broker/broker.esm.js"
    ></script>
    <script>
      window.PvtBrokerSDK = {
        brokerId: 'YOUR_BROKER_ID',
        credentials: {
          apiKey: 'YOUR_API_KEY',
          clientSecret: 'YOUR_CLIENT_SECRET',
          tenant: 'YOUR_TENANT',
          banknu: 'YOUR_BANKNU',
          env: 'YOUR_ENV',
        },
      };

      const component = document.querySelector('pvt-broker');
      const button = document.querySelector('button');  
      button.addEventListener('click', () => component.open())

      component.addEventListener('loaded', () => {
        button.disabled = false;
      });
    </script>
  </body>
</html>
```

{% hint style="success" %}
Congratulations, the Preventor Broker SDK has been successfully configured!
{% endhint %}

<figure><img src="/files/Um4imyX1K2uguZazPkHk" alt="" width="313"><figcaption><p>Web SDK</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.preventor.com/preventor-broker-sdk/web-client-side-sdks/html-+-javascript.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
