The OptiSigns TypeScript SDK provides a simple and intuitive way to manage your digital signage infrastructure programmatically. This documentation covers the main features and examples for common use cases.

Installation

npm install @optisigns/optisigns

Authentication

Initialize the SDK with your API key. Obtain your key from the account settings.

import { OptiSigns } from "@optisigns/optisigns";

const client = new OptiSigns("YOUR_API_KEY");

Core Operations

Devices

List All Devices

const devices = await client.devices.listAllDevices();

Find Device by Name

const device = await client.devices.findByDeviceName("Reception");

Get Device by ID

const device = await client.devices.getDeviceById("device_id");

Create New Device

const newDevice = await client.devices.createDevice({
  deviceName: "Reception Screen",
  orientation: "LANDSCAPE",
});

Update Device

await client.devices.updateDevice("device_id", {
  deviceName: "Updated Screen Name",
});

Delete Device

await client.devices.deleteDeviceById("device_id", "team_id");

Content Management

Upload File Asset

const asset = await client.assets.uploadFileAsset(
  "./path/to/image.jpg",
  "team_id"
);

Create Website Asset

const websiteAsset = await client.assets.createWebsiteAppAsset(
  {
    url: "https://example.com",
    title: "Company Website",
  },
  "team_id"
);

Modify Asset Settings

await client.assets.modifyAssetSettings(
  "asset_id",
  {
    name: "Updated Asset Name",
    metadata: { key: "value" },
  },
  "team_id"
);

Common Use Cases

Managing Digital Screens

  1. Push Content to Screen:
await client.devices.pushContentToDevice(
  "device_id",
  "content_id",
  "team_id",
  "NOW"
);
  1. Reboot Device:
await client.devices.rebootDevice("device_id");

Error Handling

The SDK uses TypeScript for better type safety and includes comprehensive error handling. Always wrap API calls in try-catch blocks:

try {
  const devices = await client.devices.listAllDevices();
  console.log(devices);
} catch (error) {
  console.error("Error fetching devices:", error);
}

Best Practices

  1. Error Handling: Always implement proper error handling in your applications
  2. Authentication: Keep your API key secure and never expose it in client-side code
  3. TypeScript: Take advantage of TypeScript types for better code completion and error detection
  4. Team ID: Keep track of your team ID for operations that require it

Code Examples

import { OptiSigns } from "@optisigns/optisigns";

async function manageDevices() {
  const client = new OptiSigns("YOUR_API_KEY");

  try {
    // List all devices
    const devices = await client.devices.listAllDevices();

    // Create a new device
    const newDevice = await client.devices.createDevice({
      deviceName: "Reception Screen",
      orientation: "LANDSCAPE",
    });

    // Update device name
    await client.devices.updateDevice(newDevice.id, {
      deviceName: "Updated Screen Name",
    });
  } catch (error) {
    console.error("Error:", error);
  }
}

For more detailed information, visit our API Reference or contact our support team at support@optisigns.com.