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

# SDKs

> SDKs for the Browser and NodeJS environment.

Fonoster SDKs provide you with control of a set of Fonoster resources. We currently offer SDKs for the Node.js and browser environment, and we plan to add more in the future.

## Installation

```bash theme={"system"}
$ npm install --save @fonoster/sdk
```

Or using yarn:

```bash theme={"system"}
$ yarn add @fonoster/sdk
```

Or in the browser:

```html theme={"system"}
<script src="https://unpkg.com/@fonoster/sdk"></script>
```

### Importing the library

For CommonJS projects:

```typescript theme={"system"}
const SDK = require("@fonoster/sdk");
```

For ES6 modules:

```typescript theme={"system"}
import * as SDK from "@fonoster/sdk";
```

Directly in the browser:

```html theme={"system"}
<script src="https://unpkg.com/@fonoster/sdk"></script>
<script>
   // You can now use the SDK
</script>
```

## Example

Create a new SDK instance to interact with the Fonoster API. The SDK requires a client object to handle communication with the API.

### Creating a client object

In Node.js:

```typescript theme={"system"}
const SDK = require("@fonoster/sdk");

# Replace with your Workspace's Access Key Id
const client = new SDK.Client({ accessKeyId: "WO00000000000000000000000000000000" });
```

When connecting to Fonoster's cloud services, you can omit the `endpoint` parameter.

In the browser:

```javascript theme={"system"}
const SDK = require("@fonoster/sdk");
const client = new SDK.WebClient({ accessKeyId: "WO00000000000000000000000000000000" });
```

<Note>
  Note the only difference is the name of the constructor.
</Note>

### Login in and make requests

```javascript {5} theme={"system"}
client.login("youruser@example.com", "yourpassword")
  .then(() => new SDK.Applications(client).createApplication({
    name: "MyApp",
    type: "EXTERNAL",
    endpoint: "welcome.demo.fonoster.local" // Demo application
  }))
  .then(() => console.log("Application created successfully"))
  .catch(console.error);
```

<Tip>
  In addition to the `login` method, the SDK provides a `loginWithApiKey` and `loginWithRefreshToken` methods. The `loginWithRefreshToken` is helpful in browser environments where you want to keep the user logged in between sessions.
</Tip>

<Card title="See NPM for details" icon="npm" color="#C53635" iconType="brands" href="https://www.npmjs.com/package/@fonoster/sdk">
  For full documentation, please visit NPM.
</Card>
