This documentation is actively being improved. You may encounter gaps or incomplete sections as we refine and expand the content. We appreciate your understanding and welcome any feedback to help us make this resource even better!

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

$ npm install --save @fonoster/sdk

Or using yarn:

$ yarn add @fonoster/sdk

Or in the browser:

<script src="https://unpkg.com/@fonoster/sdk"></script>

Importing the library

For CommonJS projects:

const SDK = require("@fonoster/sdk");

For ES6 modules:

import * as SDK from "@fonoster/sdk";

Directly in the browser:

<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:

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:

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

Note the only difference is the name of the constructor.

Login in and make requests

client.login("youruser@example.com", "yourpassword")
  .then(() => new SDK.Applications(client).createApplication({
    name: "MyApp",
    type: "EXTERNAL",
    endpoint: "localhost:50061"
  }))
  .then(() => console.log("Application created successfully"))
  .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.

See NPM for details

For full documentation, please visit NPM.