Getting Started

The One API project is hosted on npmjs and unpkg.

Examples are hosted in a public GitHub respository here and hosted versions can be seen here.

Installing

To install the API in to your project with npm:

npm install @activfinancial/one-api

Or with yarn:

yarn add @activfinancial/one-api

Alternatively, you can link to the CDN hosted versions of the project:

<script src="https://unpkg.com/@activfinancial/one-api"></script>

Prerequisites

This project is built on WebAssembly which sets a baseline for browser support. However, we also embrace and assume the availability of a number of modern standards which may require additional polyfilling or transpilation of your source code. These are:

The Examples section is built using Web Components. These allow the creation of custom HTML elements that can be easily imported into existing projects. Web Components are designed to be used across most modern browsers and support for them should be readily available.

Using Modules

If you are using a module loader, you can reference the individual parts of the API:

import { connect, FieldId, StatusCode } from "@activfinancial/one-api";

Otherwise, the API is available under the global namespace activOneApi:

<script src="node_modules/@activfinancial/one-api/lib/index.js"></script>
<script>

    activOneApi.connect(/* connect() options. */).then((session) => {
        // "session" now available to make requests.
    });

</script>

Connecting to the OneApi Gateway

The following snippet demonstrates how to connect and disconnect using the API:

/* global activOneApi */
// You may have to update the userId and password fields below.
const user = "__ACTIV_SESSION_USER_ID__";
const password = "__ACTIV_SESSION_PASSWORD__";
const host = "aop-ny4-replay.activfinancial.com";

(async function() {
    try {
        console.log("Connecting...");
        const session = await activOneApi.connect({
            host,
            user,
            password,
            onLogMessage(logType, message) {
                console.log(message);
            }
        });

        console.log("Connected");

        // Use the session

        console.log("Disconnecting...");

        session.disconnect();

        // The session holds a promise in the member disconnected that resolves once a disconnect has completed.
        await session.disconnected;
        console.log("Disconnected");
    } catch (e) {
        console.error(`Error: ${activOneApi.StatusCode[e]}`);
    }
})();
Try it out in the playground

The return value of connect is a Promise that resolves to an instance of Session. If the session fails to connect the Promise will be rejected with a StatusCode indicating the reason.

The properties of Session are what we'll use to interact with the API. Head to Requests to see how Session can be used.

Also in this Section