Jamesbrendamour's picture
|
download
raw
5.66 kB
---
title: Getting Started - Sage Intacct SDK for Node.js | Sage Intacct Developer
url: https://developer.intacct.com/tools/sdk-node-js/getting-started/
---
# Getting Started - Sage Intacct SDK for Node.js | Sage Intacct Developer
Overview
Getting Started
List AR Invoices
List Vendors (Legacy)
CRUD Customer
Custom Object Function
* Set up
* Understand the code
* Run the example
* Extra credit
+ Log level and format
* What’s next?
---
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:
```xml
[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:
```xml
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:
```xml
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:
```xml
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:
```xml
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:
```xml
node getting-started.js
```
2. Observe the output, for example:
```xml
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:
```xml
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:
```xml
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?
* Read the SDK overview for high level information.
* Try an example that lists AR invoices.
* Browse the reference documentation for the SDK.
Provide feedback

Xet Storage Details

Size:
5.66 kB
·
Xet hash:
462883efbd06fae9e5a63422a4627580259499c975b83a2f2ba699bb5f42479f

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.