Keyfax
  • 📋What is Keyfax?
  • Product Suite
    • Keyfax Administrator Tools
      • System Requirements
      • Installation
      • Logging On
      • Navigation
      • Exclusive Mode
      • Script Levels
        • Master Scripts
          • Category Editing
          • Topic Editing
          • Self-Service Categories
        • System Scripts
          • Cancel
          • Priority Justifications
          • Results
          • Special Instructions
          • Startup
        • Script Sets
          • Category Properties
          • Setting up Topics
          • Topic Properties
          • Loading Script Sets
      • Script Editing
        • Script Editing - The basics
        • References
        • Testing your changes
        • Script Flows
      • Script Entities
        • Databoxes
          • Script Data
            • Host-specific notes
          • SQL Query
            • Testing SQL Query Databoxes
          • Import XML
          • Export XML
          • System Values
          • Company Data
          • Testing Databoxes & Expressions
          • Databox Read
          • Databox Write
          • Databoxes in Messages & Tasks
        • Questions
          • Address
          • Checklist
          • Date/Time
          • Dynamic Lists
            • Testing Dynamic Lists
            • Dynamic List Examples
          • External Forms (eForms)
            • External Forms - Technical
          • File Upload
          • List
          • Numeric
          • Text
          • Video Call
        • Asset Data
        • Markers
        • Messages
          • Testing Messages
        • Services
          • Host-specific notes
        • Priorities
        • Tasks
          • Enclosures & Attachments
          • Continuations
          • Host-specific notes
      • Reports
      • Databox Examples
        • Business Days
        • Working Hours
        • Time of day
        • Higher priority jobs
        • Script Duration
        • How did it happen?
        • Repair Description
        • Concatenating CSV
        • Tenant Handbook
        • Multi-line Addresses
        • Priority / Response Days
        • Contains Text
      • Databox Expressions
        • Text Expressions
          • CSV
          • Entry
          • Exists
          • FieldMerge
          • Index
          • IndexOf
          • InList
          • Item
          • Len
          • ListTidy
          • Lower
          • PadLeft
          • Replace
          • Row
          • RowMerge
          • SubStr
          • Trim
          • Upper
          • WCase
        • Numeric Expressions
          • Abs
          • AsNum
          • Between
          • Int
          • Mod
          • Number
          • Result
          • Round
        • Date Expressions
          • After
          • AsDate
          • Before
          • BetweenDates
          • DateAdd
          • Day
          • Month
          • Now
          • Today
          • WeekDay
          • Year
        • Number Formatting
        • Operators And Literals
        • Logical Expressions
        • Additional Functions
          • Ds
      • Users
        • Finding active users
        • Keyfax SSO – via Microsoft Entra ID Support
      • Advanced
        • Base Task Templates
          • Email Task Templates
          • Letter Task Templates
          • Note Task Templates
          • SMS Task Templates
          • VoiceSage Task Templates
          • Host-specific notes
        • Export & Import
        • Communications Queues
      • Host Operations
        • ActiveH Operations
          • Introduction
          • Actions
          • Databoxes & UDEs
          • Emails
          • Mail Merge Letters
          • Populating CallType
          • Populating JobType
          • Repairs Inspection Task
          • Repairs Interface
        • Fast Lean Smart
      • Best Practices
        • Extracting XML from Keyfax tables
        • Script Performance
        • Handling multiple rows from SQL
        • HTML Editor
        • Writing SQL Queries
      • Known Issues
        • Startup Messages
        • Running but not Visible
        • Error 1001 During Install
        • Stopped Working
    • Keyfax Staff
      • System Requirements
      • Advisor Feedback
      • Priority and Quantity
    • Keyfax Self-Service
      • System Requirements
      • Browser Support
    • KeyNamics
      • Model Driven Apps
      • Power Pages Portals
      • Installation
        • System Requirements
        • Solution Import
        • Basic Setup
        • Known Issues
      • Embedding
        • Model Driven Apps
        • Power Pages Portals
      • Configuration
        • Settings
        • Mappings
          • Creating Mappings
          • Minimum Mapping Requirements
          • Mapping Entity Form Fields
          • Mapping Lookup fields
          • Mapping Examples
        • FetchXML
          • Creating FetchXML queries
        • Logging
        • Test
      • Advanced
        • Mode Translation Rules
        • Customising Launch Button
        • Extending Export Data
        • Mapping Dump Fields
        • Mapping JSON Results
        • Enabling Help Panes
        • Mobile Operation
        • Handling uploaded content
      • Technical
        • Topology
        • Copying Environments
        • Keyfax Startup Data
        • Keyfax Export Data
    • Keyfax Client
      • Installation
        • Getting Started
        • Launch Tester
        • Uninstall / reinstall
        • Known Issues
    • Keyfax Cloud
      • Uptime Guarantee
      • Business Continuity
  • General
    • General FAQs
      • General Questions
      • Installation Questions
      • Migration Questions
      • Security Questions
      • Test & Training Questions
    • Keyfax FAQs
      • Keyfax Administrator Tools
      • Keyfax Staff
      • Keyfax Self-Service
      • KeyNamics
      • Keyfax Client
      • Keyfax Cloud
    • Issues & Solutions
      • Emails not working
    • Release Notes
      • Keyfax
        • 4.4.7
        • 4.4.6
        • 4.4.5
        • 4.4.4
        • 4.4.3
        • 4.4.2
        • 4.4.1
        • 4.4.0
        • Previous Releases
      • Keyfax Client
        • 4.0.0.44
        • 4.0.0.43
        • 4.0.0.42
        • Previous Releases
      • KeyNamics
        • 3.0.0.0
        • 2.0.0.13
        • Previous Releases
      • Older Releases
        • Staff
  • Integrations
    • API Docs
      • REST API
        • Quick Start
        • Deep Dive
        • API SDKs
          • .NET SDK
          • JavaScript SDK
          • Start-Up Data
          • Processing Results
        • API Reference
      • SOAP API
        • Quick Start
        • Error Handling
        • Status Codes
        • XML Schemas
          • Startup Schema
          • Results Schema
          • Results with Note
          • Cancelled Schema
          • Address data
      • Legacy APIs
        • Active X
        • Asynchronous Pluggable Protocols
        • XmlHttp
    • Integrations
      • Aareon
        • Introduction
        • Launching Keyfax Repairs
        • Launching Keyfax Enquiries
        • Configuration
        • SOAP based integration
        • QL Message fields
        • Known problems
      • Accuserve
      • ActiveH Desktop
        • Introduction
        • ActiveH Repair Interface
        • Known Problems
        • Keyfax Configuration
          • MISExchange.xml
          • Example Settings
          • Retrieving Block Codes
        • MIS Configuration
          • Exchange Process
          • Exchange Elements
          • User Permissions
          • User Security
          • UDE Interface
          • UDE Configuration
          • Settings
          • Desktop Configuration
          • Priorities Configuration
          • Populating Job Type
          • Populating Assigned To
          • Populating Call Classification
          • Configuring Log Call
            • Launching Keyfax from Response Repairs
          • Workflow Integration Actions
        • MIS interface Objects
          • CRM Gateway
          • Desktop Task
          • System Task Email Addressee
          • Desktop Task Action
          • Repair Request
          • Repair Request Inspection
          • Repair Request Task
      • ActiveH Portal (TIPS)
        • Introduction
        • Settings
        • Known Issues
      • ActiveH Web
      • Breeze IT
      • Caltech
      • Capita
        • Capita Housing / Academy
          • Host Table Usage
          • Troubleshooting
        • Open Housing
      • Civica
        • Civica CX
          • Introduction
          • Mappings
          • Start Up Data
          • Inspections
          • Known Issues
        • Civica CM
          • Known problems
        • Servitor
          • Example Import XML
          • Example Export XML
      • ContactView
      • Dynamics
      • Kirona
      • Lagan
      • MIS
      • MRI
      • Northgate
        • Launching Keyfax
        • Exchange process
        • XML/Field mappings
      • OneServe
      • ROCC
      • Total Mobile
        • Launching Keyfax (TASK)
        • TotalView Configuration
      • SDM
    • Best Practices
      • Integration Considerations
      • Displaying Keyfax Self-Service
  • Technical
    • General
      • Keyfax Architecture
      • Clearing Cache
    • Cloud Operation
      • Microsoft Azure
      • Amazon Web Services
    • Configuration Settings
      • Introduction
      • Paths Element
    • Developer Zone
      • eForm Technical Details
    • SQL Server
      • Freeing Space
      • Maintaining Indexes
      • Maintenance Plan
      • Restoring Live into Test
  • Links
    • Our Web Site
    • Our Blog
    • Try Keyfax
    • Contact Us
Powered by GitBook
On this page
  • Launching Keyfax
  • Obtaining Keyfax Results
  • Renewing the JSON Web Token
  • Available SDK Methods
  1. Integrations
  2. API Docs
  3. REST API
  4. API SDKs

JavaScript SDK

Learn how to use the Keyfax Web API JavaScript SDK.

The Keyfax Web API JavaScript SDK is a self-contained JavaScript file with no external dependencies. To use the Keyfax Web API JavaScript SDK you'll need to include the Keyfax JavaScript SDK within your web pages. The following script tag should be placed towards the bottom of pages that wish to utilitize the Keyfax Web API JavaScript SDK....

<script src="https://keyfax.com/Interview/assets/js/sdks/webapi/basic/v1/sdk.min.js"></script>   

We would recommend copying and linking to this file locally within your integration and avoid linking to this file externally.

To ensure your Keyfax API signing key is never revealed to end users client side requests into the Keyfax Web API must use a JSON Web Token or JWT for verification - this is also true for our JavaScript SDK. You cannot use your API key or Signing key when using the JavaScript Web API SDK and instead need to use a JSON Web Token to verify requests.

The JWT required for client side verification should be first obtained via a secure server side call to GET /api/v1/token. This server side call will require your Keyfax Web API key and Signing key. Once the JSON Web Token has been obtained via server side code it can then be shared with the client to verify subsequent client side requests into the Keyfax Web API.

Obtaining the JSON Web Token via secure server side code is easy using the Keyfax Web API .NET SDK as shown in the following C# code example...

using Keyfax.WebApi.Sdk.Basic.v1

...

var client = new KeyfaxClient(c =>
{
    c.BaseUrl = "https://keyfax-url/interview/";
    c.HostName = "Dev";        
    c.ApiKey = "YourApiKey";
    c.SigningKey = "YourSigningKey";
});

var response = await client.GetJsonWebTokenAsync();
if (response.Success && response.Data != null)
{
    txtHiddenJWTField.Value = response.Data.Token;
}

The generated JSON Web Token will only be valid for 24 hours after creation. For long running client side sessions you should use the JSON Web Token generated by the server side call to GET /api/v1/token to call POST /api/v1/token on the client side to periodically generate a new JSON Web Token. See "Renewing the JSON Web Token" within this guide.

Once you've obtained a valid JSON Web Token via server side code you can then share this with the client and configure the Keyfax Web API JavaScript SDK as shown below...

$(document).ready(function () {

    // Get JWT generated on the server
    var $txtHiddenJWTField = $('#<% = txtHiddenJWTField.ClientID %>');

    // Add Keyfax Web API JavaScript SDK to local variable 
    var sdk = window.KeyfaxWebApiSdk;

    // Configure the JavaScript SDK, providing the Keyfax URL, host name & JSON Web Token
    sdk.init({
        url: "https://keyfaxserver.com/Interview",
        hostName: "Dev",
        token: $txtHiddenJWTField.val()
    });

});

You'll notice in the example above our server side code added the JSON Web Token to a hidden form field called txtHiddenJWTField. We then retrieve the token stored within this hidden form field via client side code to configure the Keyfax Web API JavaScript SDK. There are many ways to share content generated on the server with the client but in this example to keep things simple we used a hidden form field to store the JSON Web Token.

Once the Keyfax Web API JavaScript SDK has been configured with the URL, host name & JSON Web Token as shown above you can then use the methods provided by the Keyfax Web API JavaScript SDK to make verified requests into the Keyfax Web API.

Launching Keyfax

IMPORTANT The start -up data you provide to Keyfax should be customized to suit your environment & integration. The start -up data presented in these examples is minimal and for demonstration purposes only. Please contact Omfax Systems for assistance with configuring your start -up data to fully leverage the intelligent scripting features offered by Keyfax.

The following JavaScript shows how you can obtain Keyfax launch data via client side JavaScript code upon a button click...

// Post start-up data to get launch details on button click
$("#btnJsPostStartUpData").click(function (e) {

    e.preventDefault();

    // Get JWT generated on the server
    var $txtHiddenJWTField = $('#<% = txtHiddenJWTField.ClientID %>');

    // Add Sdk to local variable 
    var sdk = window.KeyfaxWebApiSdk;

    // Configure the client
    sdk.init({
        url: "https://keyfaxurl.com/Interview",
        hostName: "Dev",
        token: $txtHiddenJWTField.val()
    });

    // Build some sample minimal start-up date. This will need to be customized depending 
    // on your host and Keyfax configurations and is only provided for demonstration purposes
    var startUpData = {     
        mode: { value: "RD" },
        userName: { value: "administrator" },
        password: { value: "" },
        company: { value: "RDFL_Dev" },            
        scriptSet: { value: "RD" }               
    };

    // Post start-up data to get Keyfax launch data
    sdk.startup.post(startUpData, function (response) {
        if (response) {
            console.log("Url: " + response.launchUrl);
            console.log("Guid: " + response.guid);
            console.log("Company: " + response.company);
        }
    });

});

Obtaining Keyfax Results

The JavaScript below shows how to check for results for a previously launched Keyfax session using the Keyfax Web API JavaScript SDK when a button is clicked...

// Check for results using the supplied launch details
$("#btnJsPostResultsData").click(function (e) {

    e.preventDefault();

    // Get JWT generated on the server
    var $txtHiddenJWTField = $('#<% = txtHiddenJWTField.ClientID %>');

    // Add Sdk to local variable 
    var sdk = window.KeyfaxWebApiSdk;

    // Configure the client
    sdk.init({
        url: "https://keyfaxurl.com/Interview",
        hostName: "Dev",
        token: $txtHiddenJWTField.val()
    });

    // Build launch data, the results from calling sdk.startup.post
    // can also be supplied when calling sdk.results.post. 
    // These values are hard coded here for demonstration  purposes only
    var data = {
        guid: "ac712681-ce8b-443f-b317-34f5b28f22fa",
        company: "RDFL_Dev"
    };

    // Get results for the given Keyfax session via POST /api/v1/results
    sdk.results.post(data, function (response) {
        if (response) {
            console.log(JSON.stringify(response))
        }
    });

});

Renewing the JSON Web Token

Renewing the JSON Web Token is made easy using the Keyfax Web API JavaScript SDK and is just a few lines of code as shown below. By default the JSON Web Token expires after 24 hours. If you expect clients to remain within your browser application for more than 24 hours you may wish to periodically call this code to issue clients with a new token.

// Call POST /api/v1/token to obtain a new JSON Web Token
sdk.token.post(function (response) {
    if (response) {                 
        console.log("My new JSON Web Token is " + response.token);
    }
});

For this request to succeed the current JSON Web Token supplied within the Authorization header to POST /api/v1/token must still be valid. If the current JSON Web Token has expired this request will fail returning a 401 Unauthorized response.

Error Handling with the Keyfax Web API JavaScript SDK

Developers can use the onError method as shown below to handle any exceptions that may be thrown by the Keyfax Web API JavaScript SDK...

sdk.onError(function (config, xhr, ajaxOptions, thrownError) {
    console.log("Client returned an error! - " + JSON.stringify(xhr));
});

Available SDK Methods

A brief summary of each method available within the Keyfax Web API JavaScript SDK is provided below.

  • startup.get (GET /api/v1/startup) Returns minimal example start-up data for the current master configuration.

  • startup.post (POST /api/v1/startup) Post start-up data to Keyfax to obtain launch results.

  • results.post (POST /api/v1/results) Post launch results to Keyfax to obtain diagnostic results.

  • token.post (POST /api/v1/token) Renews a JSON Web Token given a currently valid JSON Web Token.

  • key.get (GET /api/v1/key) Obtain initial API & Signing Keys for authentication.

Previous.NET SDKNextStart-Up Data

Last updated 1 year ago