.intro.md•3.09 kB
sdk
=================
[](https://fonoster.com)
[](https://npmjs.org/package/@fonoster/sdk)
[](https://npmjs.org/package/@fonoster/sdk)
[](https://github.com/fonoster/fonoster/blob/main/package.json)
This package provides a set of utilities for working with Fonoster services. It is a polymorphic SDK that can be used in a browser or a Node.js environment.
* [Installation](#installation)
* [Example](#example)
* [APIs](#apis)
## Installation
```sh-session
$ npm install --save @fonoster/sdk
```
Or using yarn:
```sh-session
$ yarn add @fonoster/sdk
```
Or in the browser:
```html
<script src="https://unpkg.com/@fonoster/sdk"></script>
```
### Importing the library
For CommonJS projects:
```typescript
const SDK = require("@fonoster/sdk");
```
For ES6 modules:
```typescript
import * as SDK from "@fonoster/sdk";
```
Directly in the browser:
```html
<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
const SDK = require("@fonoster/sdk");
const ACCESS_KEY_ID = "WO00000000000000000000000000000000";
const ENDPOINT = "api.fonoster.com";
const client = new SDK.Client({ accessKeyId: ACCESS_KEY_ID, endpoint: ENDPOINT });
```
When connecting to Fonoster's cloud services, you can omit the `endpoint` parameter.
In the browser:
```typescript
const SDK = require("@fonoster/sdk");
const ACCESS_KEY_ID = "WO00000000000000000000000000000000";
const URL = "https://api.fonoster.com/v1beta2";
const client = new SDK.WebClient({ accessKeyId: ACCESS_KEY_ID, url: URL });
```
When connecting to Fonoster's cloud services, you can omit the `url` parameter.
### Login in and make requests
```typescript
const username = "admin@fonoster.local";
const password = "changeme";
async function main() {
await client.login(username, password);
const applications = new SDK.Applications(client);
await applications.createApplication({
name: "MyApp",
type: "EXTERNAL",
endpoint: "localhost:50061" // Your app's endpoint
});
}
main().catch(console.error);
```
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.
The SDK will automatically refresh the token when it expires.
## APIs
* [`Applications`](#Applications)
* [`Acls`](#Acls)
* [`Agents`](#Agents)
* [`ApiKeys`](#ApiKeys)
* [`Calls`](#Calls)
* [`Credentials`](#Credentials)
* [`Domains`](#Domains)
* [`Numbers`](#Numbers)
* [`Secrets`](#Secrets)
* [`Trunks`](#Trunks)
* [`Users`](#Users)
* [`Workspaces`](#Workspaces)