Overview

Get going quickly using Web Services with the Sage Intacct SDK for Node.js.

The SDK allows you to work with pre-built objects instead of directly with the underlying XML API.

The Sage Intacct SDK for Node.js is licensed under Apache v2.0. Please read and accept this before using the SDK.

This topic provides a high-level overview of the SDK. When you are ready to start coding, try the getting started example and keep the reference documentation handy for delving deeper.

If the SDK does not provide the functionality you need, you can write your own classes that implement functions. See Custom Object Function for an example.


System Requirements


Quick Install

Install the SDK using npm:

npm install @intacct/intacct-sdk

You can also visit the npm package page.


Client model

The SDK uses a client model for sending requests to the gateway. You construct a client, optionally configure it, then use it to execute your requests.

There are two kinds of clients:

Both clients provide an execute call that sends a single API function, and an executeBatch function for sending multiple functions. For usage information, see the getting started example.


Client configuration

When you construct a client, you can optionally provide configuration information in a client configuration object. This object can provide Web Services credentials, company credentials (including an optional entity ID), a session ID, logger choices, the gateway endpoint, and so forth.

const IA = require("@intacct/intacct-sdk");
let clientConfig = new IA.ClientConfig(); // Create the config and set a session ID
clientConfig.sessionId = "SomeSessionFromTheInternet..";

const client = new IA.OnlineClient(clientConfig); // Construct the client with the config

During client instantiation, the default endpoint (https://api.intacct.com/ia/xml/xmlgw.phtml) is used.


Request configuration

To configure the request that is sent to the gateway by the SDK, create a request configuration instance and pass it in when you call execute or executeBatch.

You can use a request configuration to set a control ID for the request, specify a transport policy ID (for an offline client), set a time-out value, and so forth.

const IA = require("@intacct/intacct-sdk");
let requestConfig = new IA.RequestConfig(); // Create the request config and set a control ID
requestConfig.controlId = "testing123";

const response = await client.execute(query, requestConfig); // Execute the request and await the response

If you do not supply a request configuration, the following defaults are used.

controlId = Date.now().toString();
encoding = "utf-8";
maxRetries = 5;
maxTimeout = 30000; // milliseconds
noRetryServerErrorCodes = [ 524 ]; // CDN cut the connection, but the system is still processing
policyId = "";
transaction = false;
uniqueId = false;

For a high-level understanding of how you can configure requests, see XML Requests.


API functions

The underlying API functions are made available through classes in the Intacct/SDK/Functions module. The classes that provide object-specific functionality are under feature names, and the classes that provide generic functionality are in a single name. For example, object-specific classes such as CustomerCreate, JournalEntryCreate, and ContactUpdate are under their respective categories, and generic classes such as Read and ReadByQuery are under a single Common module.

All these classes implement the IFunction interface and extend AbstractFunction, which gives them access to an XML writer that translates the objects into XML.

The clients can execute any class implementations of the IFunction. If the Intacct/SDK/Functions classes do not meet your needs, you are welcome to write your own classes that implement this interface. Check out Custom Object Function for more on this.

The following example constructs a ReadByQuery instance that queries for vendors:

const IA = require("@intacct/intacct-sdk");
let query = new IA.Functions.Common.ReadByQuery();
query.objectName = "VENDOR"; // Keep the count to just 1 for the example
query.pageSize = 1;
query.fields = [
    "RECORDNO",
    "VENDORID",
    "NAME",
];

Credentials

There are several ways you can supply Web Services and company credentials (including an optional entity ID) to the SDK.

You can mix and match how credentials are loaded. For example, you might set Web Services credentials in your environment, then load company login credentials from a credentials file. You can also pass company credentials directly to the ClientConfig from a different source.

Hard-coded credentials

The following shows how to provide hard-coded Web Services and company credentials using ClientConfig:

const IA = require("@intacct/intacct-sdk");
let config = new IA.ClientConfig();
config.senderId = "testsenderid";
config.senderPassword = "pass123!";
config.companyId = "testcompany";
// config.entityId = "testentity";
config.userId = "testuser";
config.userPassword = "testpass";

Note: You should make every effort to securely store your credentials and not hard code them.

Environment variables

You can use environment variables to specify credentials directly or via named profiles in a credentials file. You can also override the default gateway endpoint using an environment variable.

Variable Description
INTACCT_SENDER_ID, INTACCT_SENDER_PASSWORD Web Services credentials.
INTACCT_COMPANY_ID, INTACCT_ENTITY_ID, INTACCT_USER_ID, INTACCT_USER_PASSWORD Company login credentials.
INTACCT_SENDER_PROFILE, INTACCT_COMPANY_PROFILE,INTACCT_PROFILE Names of profiles in a credentials file. Using these variables causes the client to load credentials from the given profile in the credentials file in use.
INTACCT_ENDPOINT_URL Overrides the default endpoint URL.

Credentials file and profiles

If not otherwise supplied, the SDK will look for credentials in the default profile in a credentials file in the default location:

home_dir/.intacct/credentials.ini

The following shows the format for the file. Each profile starts with a name in brackets followed by key/value pairs.

[default]
sender_id = mysenderid
sender_password = mysenderpassword
company_id = mycompanyid
user_id = myuserid
user_password = myuserpassword

[demo987654321]
company_id = demo987654321
user_id = myuserid
user_password = myuserpassword

[demo987654321_entityA]
company_id = demo987654321
user_id = myuserid
user_password = myuserpassword
entity_id = entityA

[dev123]
sender_id = mysenderid
sender_password = mysenderpassword
endpoint_url = https://api.intacct.com/ia/xml/xmlgw.phtml

You can provide values for the following in any profile:

Override the location for the credentials file

You can override the default location of the credentials file with the ClientConfig.profileFile string property:

const IA = require("@intacct/intacct-sdk");
const path = require("path");

let clientConfig = new IA.ClientConfig();
clientConfig.profileFile = path.join(__dirname, "SomeFileNotInSourceControl.ini");
clientConfig.profileName = "demo987654321";

const client = new IA.OnlineClient(clientConfig);

Use a non-default profile name

As shown above, you can specify a non-default profile to use with ClientConfig.profileName. You can also use the INTACCT_SENDER_PROFILE, INTACCT_COMPANY_PROFILE, or INTACCT_PROFILE environment variables for this purpose.

Session credentials

Some integrations are triggered by Smart Event HTTP notifications. Such notifications typically include a session ID and endpoint URL.

Warning: Do not blindly trust session IDs that your server receives over the internet. Always validate these parameters before using them.

You can use the static SessionProvider.factory function to validate that a session ID is valid and that the endpoint URL is a *.intacct.com domain.

try {
    const IA = require("@intacct/intacct-sdk");
    let config = new IA.ClientConfig();
    // Web Services credentials are loaded from the environment
    // Assume the following endpoint and session ID came from an HTTP POST (after using sanitize filters)
    config.endpointUrl = "https://api.intacct.com/ia/xml/xmlgw.phtml";
    config.sessionId = "SomeSessionFromTheInternet..";

    // Validate that the session ID is valid and the endpoint URL is a *.intacct.com domain
    let sessionConfig = await IA.SessionProvider.factory(config);

    // Create a client with the validated session credentials in a new ClientConfig
    const client = new IA.OnlineClient(sessionConfig);

    // Execute some other API functions
} catch (ex) {
    console.log(ex);
    throw ex;
}

Client/entity slide-in credentials

The following table shows another way to provide entity slide-in credentials using the pipe character (|) to separate the IDs.

Description Company ID
Client linked from your console myConsoleId|clientCompanyId
Entity level of a company companyId|entityId
Entity level of a company for a client linked from your console myConsoleId|clientCompanyId|entityId

Error handling

There are several categories of errors that can occur when sending requests to the gateway. Your code should handle these.

Exception Description
IntacctException An IntacctException extends the built-in Error and is likely an issue with Sage Intacct itself.
ResponseException A ResponseException extends the built-in Error and is likely a problem with the client or request configuration. For example, you might have invalid Web Services credentials or invalid company credentials.
ResultException A ResultException extends the Intacct/SDK/Exceptions/ResponseException and is likely a problem with an API function being executed.

The execute and executeBatch functions have some built-in error handling for the results (Result instances) coming back:


Logging

The SDK uses Winston, which is a popular logging framework used throughout the SDK examples.

A logger can be set using the ClientConfig.logger function. If set, the SDK will add entries for all HTTP request and responses with the Sage Intacct API endpoint.

By default, the SDK writes log entries using the debug log level. To change the level, use ClientConfig.logLevel. If you change the level, consider changing the format to omit the XML request and response as these can get quite large.

To format the entries differently, construct a new MessageFormatter object and add it to the config with ClientConfig.logMessageFormatter.

The logger will attempt to redact sensitive info, like passwords, from the debug entries. Regardless, access to logs should always be restricted.


What’s Next?

Provide feedback