This tutorial will get you up and running quickly with the Sage Intacct SDK for Node.js. Make sure you meet the system requirements before continuing.


Set up

  1. Download and install Node.js if you do not already have it installed.

  2. Download or clone the Sage Intacct SDK for Node.js examples.

  3. Create a new Node.js project for the examples in your IDE of choice (WebStorm, Visual Studio, etc.).

  4. Note that the package.json file (in the project root) specifies the Sage Intacct SDK for Node.js as a dependency:

    "@intacct/intacct-sdk": "^1.0.0",
    
  5. Open a terminal window in the root folder and run npm install.

    This creates a node_modules folder and adds the Sage Intacct SDK for Node.js libraries and dependencies.

  6. Create a credentials.ini file in the root folder and provide your developer/sandbox credentials as follows:

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

    The default profile is automatically used unless overridden in the ClientConfig or by environment variables.

    Note: The credentials file is excluded from source control via the .gitignore file. You should take precautions to secure this file.


Understand the code

  1. Take a look at bootstrap.js in the project root and note that it:

    • Has an export logger function for setting up a winston logger:

      exports.logger = function() {
          const winston = require("winston");
          const path = require("path");
           
          return new winston.Logger({
              transports: [
                  new winston.transports.File({
                      level: "debug",
                      filename: path.join(__dirname, "logs", "intacct.log"),
                  }),
              ]
          });
      };
      
    • Has an export client function for setting up a client config that relies on your credentials file and returns a new online client that uses the client config:

      exports.client = function (logger) {
          const IA = require("@intacct/intacct-sdk");
          const path = require("path");
           
          const clientConfig = new IA.ClientConfig();
          clientConfig.profileFile = path.join(__dirname, "credentials.ini");
          clientConfig.logger = logger;
           
          return new IA.OnlineClient(clientConfig);
      };
      
  2. Open getting-started.js and note that it:

    • Constructs a ReadByQuery instance that queries for vendors:

      const query = new IA.Functions.Common.ReadByQuery();
      query.objectName = "VENDOR";
      query.pageSize = 1; // Keep the count to just 1 for the example
      query.fields = [
          "RECORDNO",
          "VENDORID",
          "NAME",
      ];
      
    • Executes the query using the online client instance (client) that was instantiated in the bootstrap file:

      const response = await client.execute(query);
      const result = response.getResult();
      ...
      console.log("Success! Number of vendor objects found: " + result.totalCount.toString());
      

Run the example

  1. Run the getting-started.js file:

    node getting-started.js
    
  2. Observe the output, for example:

    Success! Number of vendor objects found: 14
       
    Process finished with exit code 0
    
  3. Open the generated logs/intacct.log file in a text editor and review the entries.

    The SDK provided one debug entry for the HTTP request with the Sage Intacct endpoint (/ia/xml/xmlgw.phtml HTTP/1.1), and another for the single response. The response includes the request control ID, which defaults to the timestamp of the request, and the function control ID, which defaults to a random UUID.


Extra credit

Log level and format

  1. Edit the export client function in the bootstrap.js file to change the SDK’s log message format and log level. This is done by adding logLevel and logMessageFormatter property setters:

    exports.client = function (logger) {
        const IA = require("@intacct/intacct-sdk");
        const path = require("path");
       
        const clientConfig = new IA.ClientConfig();
        clientConfig.profileFile = path.join(__dirname, "credentials.ini");
        clientConfig.logger = logger;
        clientConfig.logLevel = "info"; // add this line
        clientConfig.logMessageFormatter = new IA.Logging.MessageFormatter("\"{method} {target} HTTP/{version}\" {code}"); // add this line
       
        return new IA.OnlineClient(clientConfig);
    };
    
  2. Run the project again, then open logs/intacct.log and review the new entries at the bottom. Note the response code is listed after the HTTP method in the second info block.


What’s next?

Provide feedback