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 (intacct/intacct-sdk) as a dependency.

  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.createLogger({
               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");
           
          let 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 Read instance that accesses field data for the customer whose record number is 33:

      let read = new IA.Functions.Common.Read();
      read.objectName = "CUSTOMER";
      read.fields = [
          "RECORDNO", "CUSTOMERID", "NAME"
      ]
      read.keys = [
          33
      ];
      
    • Executes the request using the online client instance (client) that was instantiated in the bootstrap file:

      const response = await client.execute(read);
      const result = response.getResult();
      // ...
      let json_data = result.data;
      
      console.log("Result:");
      console.log( JSON.stringify(json_data) )
      

Run the example

  1. Run the getting-started.js file:

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

    Result:
    [{"RECORDNO":"33","CUSTOMERID":"10182","NAME":"Ria Jones"}]
    
  3. If you don’t get a result, replace the record number with ones that can be found in your company, for example:

         read.keys = [
             12,10,44
         ];
    
  4. Open the generated log file, for example, logs\intacct.log, and examine 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");
       
        let 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