Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Node.js Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
FileAccess
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)

Java KeyStore (JKS)
Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(Node.js) QuickBooks - Query Employees

Demonstrates how to query the QuickBooks employee data.

Install Chilkat for Node.js and Electron using npm at

Chilkat npm packages for Node.js

Chilkat npm packages for Electron

on Windows, Linux, MacOSX, and ARM

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node11-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node11-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node11-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node11-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node11-linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('@chilkat/ck-node11-macosx');
}

function chilkatExample() {

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // This example also assumes an OAuth1 access token was previously fetched.
    // and saved in a JSON file.  See the Chilkat online examples at example-code.com
    // for Quickbooks OAuth1 examples (in the Quickbooks and OAuth1 categories)
    // 

    // First get our previously obtained access token.
    var jsonToken = new chilkat.JsonObject();
    var success = jsonToken.LoadFile("qa_data/tokens/quickbooks.json");

    var oauth1 = new chilkat.OAuth1();
    oauth1.ConsumerKey = "QUICKBOOKS_CONSUMER_KEY";
    oauth1.ConsumerSecret = "QUICKBOOKS_CONSUMER_SECRET";
    oauth1.Token = jsonToken.StringOf("oauth_token");
    oauth1.TokenSecret = jsonToken.StringOf("oauth_token_secret");

    var rest = new chilkat.Rest();

    // Connect using TLS.
    // A single REST object, once connected, can be used for many Quickbooks REST API calls.
    // The auto-reconnect indicates that if the already-established HTTPS connection is closed,
    // then it will be automatically re-established as needed.
    var bAutoReconnect = true;
    success = rest.Connect("sandbox-quickbooks.api.intuit.com",443,true,bAutoReconnect);
    if (success !== true) {
        console.log(rest.LastErrorText);
        return;
    }

    rest.SetAuthOAuth1(oauth1,false);

    // The company ID is the realmId
    var sbPath = new chilkat.StringBuilder();
    sbPath.Append("/v3/company/<companyID>/query");
    var numReplacements = sbPath.Replace("<companyID>",jsonToken.StringOf("realmId"));

    rest.AddHeader("Accept","application/json");
    rest.AllowHeaderFolding = false;

    var query = "select * from Employee";
    rest.AddQueryParam("query",query);
    rest.AddQueryParam("minorversion","4");

    var responseBody = rest.FullRequestNoBody("GET",sbPath.GetAsString());
    if (rest.LastMethodSuccess !== true) {
        console.log(rest.LastErrorText);
        return;
    }

    // We should expect a 200 response if successful.
    if (rest.ResponseStatusCode !== 200) {
        console.log("Request Header: ");
        console.log(rest.LastRequestHeader);
        console.log("----");
        console.log("Response StatusCode = " + rest.ResponseStatusCode);
        console.log("Response StatusLine: " + rest.ResponseStatusText);
        console.log("Response Header:");
        console.log(rest.ResponseHeader);
        console.log(responseBody);
        return;
    }

    // Load the JSON response into a JSON object for parsing.
    // A sample JSON response is shown below.
    var json = new chilkat.JsonObject();
    json.Load(responseBody);

    // Show the full JSON response.
    json.EmitCompact = false;
    console.log(json.Emit());

    // These will be used for parsing date/time strings..
    var dtime = new chilkat.CkDateTime();
    var bLocalTime = true;
    // dt: DtObj
    var dt;

    // Iterate over each account returned.
    var numRecords = json.SizeOfArray("QueryResponse.Employee");
    var i = 0;
    while (i < numRecords) {

        json.I = i;
        console.log("DisplayName: " + json.StringOf("QueryResponse.Employee[i].DisplayName"));
        console.log("Id: " + json.StringOf("QueryResponse.Employee[i].Id"));
        console.log("Active: " + json.BoolOf("QueryResponse.Employee[i].Active"));

        // Load the CreateTime into a CkDateTime...
        dtime.SetFromTimestamp(json.StringOf("QueryResponse.Employee[i].MetaData.CreateTime"));
        dt = dtime.GetDtObj(bLocalTime);
        console.log(dt.Month + "/" + dt.Day + "/" + dt.Year + "  " + dt.Hour + ":" + dt.Minute);

        // The the birth year, month, and day, if it exists.
        // The BirthDate contains something like this: "1985-09-11"
        if (json.HasMember("QueryResponse.Employee[i].BirthDate") == true) {
            var sTab = new chilkat.StringTable();
            sTab.SplitAndAppend(json.StringOf("QueryResponse.Employee[i].BirthDate"),"-",true,true);
            var year = sTab.StringAt(0);
            var month = sTab.StringAt(1);
            var day = sTab.StringAt(2);
            console.log("BirthDate: " + month + "/" + day + "/" + year);
        }

        console.log("----");
        i = i+1;
    }

    console.log("Success.");

    // ------------------------------------------------------
    // The JSON response looks like this:

    // {
    //   "QueryResponse": {
    //     "Employee": [
    //       {
    //         "BillableTime": false,
    //         "domain": "QBO",
    //         "sparse": false,
    //         "Id": "55",
    //         "SyncToken": "0",
    //         "MetaData": {
    //           "CreateTime": "2016-09-15T11:21:48-07:00",
    //           "LastUpdatedTime": "2016-09-15T11:21:48-07:00"
    //         },
    //         "GivenName": "Emily",
    //         "FamilyName": "Platt",
    //         "DisplayName": "Emily Platt",
    //         "PrintOnCheckName": "Emily Platt",
    //         "Active": true
    //       },
    //       {
    //         "BillableTime": false,
    //         "BirthDate": "1985-09-11",
    //         "HiredDate": "2016-08-17",
    //         "domain": "QBO",
    //         "sparse": false,
    //         "Id": "54",
    //         "SyncToken": "1",
    //         "MetaData": {
    //           "CreateTime": "2016-09-15T11:21:28-07:00",
    //           "LastUpdatedTime": "2016-09-15T11:46:26-07:00"
    //         },
    //         "GivenName": "John",
    //         "FamilyName": "Johnson",
    //         "DisplayName": "John Johnson",
    //         "PrintOnCheckName": "John Johnson",
    //         "Active": true,
    //         "PrimaryPhone": {
    //           "FreeFormNumber": "(540) 555-9645"
    //         }
    //       },
    //       {
    //         "SSN": "XXX-XX-XXXX",
    //         "PrimaryAddr": {
    //           "Id": "98",
    //           "Line1": "45 N. Elm Street",
    //           "City": "Middlefield",
    //           "CountrySubDivisionCode": "CA",
    //           "PostalCode": "93242"
    //         },
    //         "BillableTime": false,
    //         "domain": "QBO",
    //         "sparse": false,
    //         "Id": "60",
    //         "SyncToken": "0",
    //         "MetaData": {
    //           "CreateTime": "2016-10-25T14:08:18-07:00",
    //           "LastUpdatedTime": "2016-10-25T14:08:18-07:00"
    //         },
    //         "GivenName": "John",
    //         "FamilyName": "Meuller",
    //         "DisplayName": "John Meuller",
    //         "PrintOnCheckName": "John Meuller",
    //         "Active": true,
    //         "PrimaryPhone": {
    //           "FreeFormNumber": "408-525-1234"
    //         }
    //       }
    //     ],
    //     "startPosition": 1,
    //     "maxResults": 3
    //   },
    //   "time": "2016-10-25T14:18:38.487-07:00"
    // 

}

chilkatExample();

 

© 2000-2016 Chilkat Software, Inc. All Rights Reserved.