Getting Started
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
-
Download and install Node.js if you do not already have it installed.
-
Download or clone the Sage Intacct SDK for Node.js examples.
-
Create a new Node.js project for the examples in your IDE of choice (WebStorm, Visual Studio, etc.).
-
Note that the
package.json
file in the project root specifies the Sage Intacct SDK for Node.js (intacct/intacct-sdk
) as a dependency. -
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. -
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 theClientConfig
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
-
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); };
-
-
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
-
Run the
getting-started.js
file:node getting-started.js
-
Observe the output, for example:
Result: [{"RECORDNO":"33","CUSTOMERID":"10182","NAME":"Ria Jones"}]
-
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 ];
-
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
-
Edit the export
client
function in thebootstrap.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); };
-
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?
- Read the SDK overview for high level information.
- Try an example that lists AR invoices.
- Browse the reference documentation for the SDK.