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

Java 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

 

 

 

(Java) QuickBooks - Query an Account

Demonstrates how to query the QuickBooks chart of accounts.

Chilkat Java Downloads

Java Libs for Windows, Linux, Alpine Linux,
MAC OS X, Solaris, FreeBSD, OpenBSD,
Raspberry Pi and other single board computers

Java Libs for Android

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    //  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.
    CkJsonObject jsonToken = new CkJsonObject();
    boolean success = jsonToken.LoadFile("qa_data/tokens/quickbooks.json");

    CkOAuth1 oauth1 = new CkOAuth1();
    oauth1.put_ConsumerKey("QUICKBOOKS_CONSUMER_KEY");
    oauth1.put_ConsumerSecret("QUICKBOOKS_CONSUMER_SECRET");
    oauth1.put_Token(jsonToken.stringOf("oauth_token"));
    oauth1.put_TokenSecret(jsonToken.stringOf("oauth_token_secret"));

    CkRest rest = new CkRest();

    //  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.
    boolean bAutoReconnect = true;
    success = rest.Connect("sandbox-quickbooks.api.intuit.com",443,true,bAutoReconnect);
    if (success != true) {
        System.out.println(rest.lastErrorText());
        return;
        }

    rest.SetAuthOAuth1(oauth1,false);

    //  The company ID is the realmId
    CkStringBuilder sbPath = new CkStringBuilder();
    sbPath.Append("/v3/company/<companyID>/query");
    int numReplacements = sbPath.Replace("<companyID>",jsonToken.stringOf("realmId"));

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

    String query = "select * from Account where Metadata.CreateTime > '2014-12-31'";
    rest.AddQueryParam("query",query);

    String responseBody = rest.fullRequestNoBody("GET",sbPath.getAsString());
    if (rest.get_LastMethodSuccess() != true) {
        System.out.println(rest.lastErrorText());
        return;
        }

    //  We should expect a 200 response if successful.
    if (rest.get_ResponseStatusCode() != 200) {
        System.out.println("Request Header: ");
        System.out.println(rest.lastRequestHeader());
        System.out.println("----");
        System.out.println("Response StatusCode = " + rest.get_ResponseStatusCode());
        System.out.println("Response StatusLine: " + rest.responseStatusText());
        System.out.println("Response Header:");
        System.out.println(rest.responseHeader());
        System.out.println(responseBody);
        return;
        }

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

    //  These will be used for parsing date/time strings..
    CkDateTime dtime = new CkDateTime();
    boolean bLocalTime = true;
    CkDtObj dt;

    //  Iterate over each account returned.
    int numAccounts = json.SizeOfArray("QueryResponse.Account");
    int i = 0;
    while (i < numAccounts) {

        json.put_I(i);
        System.out.println("Name: " + json.stringOf("QueryResponse.Account[i].Name"));
        System.out.println("Id: " + json.stringOf("QueryResponse.Account[i].Id"));

        //  Load the CreateTime into a CkDateTime...
        dtime.SetFromTimestamp(json.stringOf("QueryResponse.Account[i].MetaData.CreateTime"));
        dt = dtime.GetDtObj(bLocalTime);
        System.out.println(dt.get_Month() + "/" + dt.get_Day() + "/" + dt.get_Year() + "  " + dt.get_Hour() + ":"
             + dt.get_Minute());

        System.out.println("----");
        i = i+1;
        }

    System.out.println("Success.");

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

    //  {
//   "QueryResponse": {
//     "Account": [
    //        {
//         "Name": "Accounts Payable (A/P)",
    //          "SubAccount": false,
    //          "FullyQualifiedName": "Accounts Payable (A/P)",
    //          "Active": true,
    //          "Classification": "Liability",
    //          "AccountType": "Accounts Payable",
    //          "AccountSubType": "AccountsPayable",
    //          "CurrentBalance": -1602.67,
    //          "CurrentBalanceWithSubAccounts": -1602.67,
    //          "CurrencyRef": {
//           "value": "USD",
    //            "name": "United States Dollar"
    //          },
    //          "domain": "QBO",
    //          "sparse": false,
    //          "Id": "33",
    //          "SyncToken": "0",
    //          "MetaData": {
//           "CreateTime": "2016-09-10T10:12:02-07:00",
    //            "LastUpdatedTime": "2016-09-17T13:10:36-07:00"
    //          }
    //        },
    //        {
//         "Name": "Accounts Receivable (A/R)",
    //          "SubAccount": false,
    //          "FullyQualifiedName": "Accounts Receivable (A/R)",
    //          "Active": true,
    //          "Classification": "Asset",
    //          "AccountType": "Accounts Receivable",
    //          "AccountSubType": "AccountsReceivable",
    //          "CurrentBalance": 5281.52,
    //          "CurrentBalanceWithSubAccounts": 5281.52,
    //          "CurrencyRef": {
//           "value": "USD",
    //            "name": "United States Dollar"
    //          },
    //          "domain": "QBO",
    //          "sparse": false,
    //          "Id": "84",
    //          "SyncToken": "0",
    //          "MetaData": {
//           "CreateTime": "2016-09-14T14:49:29-07:00",
    //            "LastUpdatedTime": "2016-09-17T13:16:17-07:00"
    //          }
    //        },
    //        {
//         "Name": "Advertising",
    //          "SubAccount": false,
    //          "FullyQualifiedName": "Advertising",
    //          "Active": true,
    //          "Classification": "Expense",
    //          "AccountType": "Expense",
    //          "AccountSubType": "AdvertisingPromotional",
    //          "CurrentBalance": 0,
    //          "CurrentBalanceWithSubAccounts": 0,
    //          "CurrencyRef": {
//           "value": "USD",
    //            "name": "United States Dollar"
    //          },
    //          "domain": "QBO",
    //          "sparse": false,
    //          "Id": "7",
    //          "SyncToken": "0",
    //          "MetaData": {
//           "CreateTime": "2016-09-09T14:42:07-07:00",
    //            "LastUpdatedTime": "2016-09-09T14:42:07-07:00"
    //          }
    //        },
    //  ...
    //    "time": "2016-10-24T15:35:25.067-07:00"
    //  }
  }
}

 

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