> For the complete documentation index, see [llms.txt](https://docs.dataswyft.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dataswyft.com/build/advanced-topics/pda-authentication/password-management/tutorials/data-api.md).

# JavaScript

### Overview

This library contains all the API calls needed to communicate with the HAT.

* Authentication
* Fetch Applications, Data Plugs and Data Debits
* Read and write data to endpoints
* File API

## Setting Up Environment

### Supported Environments

The @dataswift/hat-js library works in all modern browsers. Some older browsers do not support all the features required. If you want to support these browsers you need to load polyfill for [Promise](https://github.com/taylorhakes/promise-polyfill).

### Installation

Install the **@dataswift/hat-js** package via [npm](https://www.npmjs.com/package/@dataswift/hat-js) or pull from our CDN.

**NPM installation**

```
npm install @dataswift/hat-js
```

**CDN Link**

```
<script src="https://cdn.dataswift.io/libs/hatjs/hat-0.3.0.min.js"></script>
```

### Usage

#### Importing

**ES6**

```javascript
import { HatClient } from "@dataswift/hat-js";
```

**ES5 Modules**

```javascript
var HatClient = require("@dataswift/hat-js").HatClient;
```

#### Initialisation

**Configuration type:**

```typescript
interface HatClientConfig {
    apiVersion?: string; // Api Version for the HAT. eg. v2.6
    hatDomain?: string; // The HAT domain of the user. eg. testing.hubat.net
    token?: string; // The Application token.
    secure?: boolean; // If you want to run the HAT locally, you have to modify this field to 'false'.
    onTokenChange?: Function;
}
```

**Example:**

```javascript
const config = {
    token: "<access-token>",
    apiVersion: 'v2.6',
    secure: true,
    onTokenChange: (newToken) => storeNewToken(newToken)
};

const hat = new HatClient(config);
```

###


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.dataswyft.com/build/advanced-topics/pda-authentication/password-management/tutorials/data-api.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.
