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: "welcome.demo.fonoster.local" // Demo application
  }))
  .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.

See NPM for details

For full documentation, please visit NPM.

Was this page helpful?