node-quickbooks

repository·master·Indexed 18 days ago

https://github.com/mcohen01/node-quickbooks

A Node.js client and wrapper for Intuit's IPP QuickBooks V3 API (version 2.0.49). It provides a simplified interface for CRUD operations, reporting, and PDF management, including support for oAuth 2. The library includes a wide range of methods for managing entities such as accounts, customers, invoices, and vendors, as well as tools for query filtering, pagination, and financial report generation.

Tokens
10.5K
Snippets
19
Records
47
Agent score
13%

What's inside node-quickbooks

  1. How to sort, paginate, and count results in queries

    master

    You can control the result set of query functions using keys within the optional first argument object.

    Sorting

    Use the asc or desc keys. The value should be the column name you wish to sort on.

    qbo.findAttachables({
      desc: 'MetaData.LastUpdatedTime'
    }, function(e, attachables) {
      console.log(e, attachables)
    })

    Pagination

    Use limit (number of rows to return) and offset (number of rows to skip).

    qbo.findAttachables({
      limit: 10,
      offset: 10
    }, function(e, attachables) {
      console.log(e, attachables)
    })

    Fetch All Records

    By default, the maximum limit is 1000 records. To transparently fetch all available records (issuing multiple requests as needed), set fetchAll: true.

    qbo.findCustomers({
      fetchAll: true
    }, function(e, customers) {
      console.log(customers)
    })

    Row Counts

    To get the total count of rows instead of the full result set, pass count: true.

    qbo.findAttachables({
      count: true
    }, function(e, attachables) {
      console.log(e, attachables)
    })
  2. How query filters work in node-quickbooks

    master

    All query functions (e.g., findAttachables, findCustomers) accept an optional first argument object to build a WHERE clause.

    Simple Filters

    Pass an object where keys are column names and values are the parameter values. This generates a simple equality check.

    qbo.findAttachables({
      Note: 'My sample note field'
    }, function(e, attachables) {
      console.log(attachables)
    })

    Complex Filters with Operators

    To use operators like =, IN, <, >, <=, >=, or LIKE, pass an array of objects. Each object must specify a field, a value, and an optional operator.

    qbo.findTimeActivities([
      {field: 'TxnDate', value: '2014-12-01', operator: '>'},
      {field: 'TxnDate', value: '2014-12-03', operator: '<'},
      {field: 'limit', value: 5}
    ], function (e, timeActivities) {
      console.log(timeActivities)
    })
  3. Setup the QuickBooks Example App

    master

    The example directory contains an Express application demonstrating the OAuth workflow.

    1. Navigate and Install:
      cd example
      npm install
    2. Configure Credentials: Create an Intuit Developer account and add your OAuth Consumer Key and Secret to app.js.
    3. API Selection: If you did not select both 'Payments' and 'QuickBooks' APIs during app creation, you must update example/views/intuit.ejs.
    4. Run the App:
      node app.js
    5. Authenticate: Browse to http://localhost:3000/start and click the Intuit Developer button to begin the OAuth exchange.
  4. Running tests for node-quickbooks

    master

    To run the test suite, you must first provide valid credentials in config.js.

    1. Obtain Credentials: The easiest way to get consumerKey, consumerSecret, token, tokenSecret, and realmId is to run the example app, complete the OAuth workflow, and copy the values logged to the console.
    2. Update Config: Fill in the missing values in config.js.
    3. Execute Tests:
      npm test
  5. How query criteria are constructed

    master

    When using find* methods or the underlying query logic, you can pass criteria to filter results. The library converts these into a SQL WHERE clause.

    Supported Criteria Types:

    1. String: A direct SQL fragment. Note that the library handles some character escaping.
    2. Object: A map where keys are field names and values are the filter values. A single-valued object is converted to where key = 'value'. Multiple keys are joined with AND.
    3. Array of Objects: Allows for more complex filtering. Each object in the array represents a criterion.

    Special Fields in Criteria:

    • limit: Sets the maximum number of results (default is 1000).
    • offset: Sets the starting position (default is 1).
    • fetchAll: A boolean. If true, the library will automatically perform multiple requests to fetch all available records by incrementing the offset.
    • desc / asc: Used for ordering results (e.g., { desc: true }).
    • count: If a criterion object contains a count property, the query is transformed into a SELECT COUNT(*) query.
  6. Retrieve Exchange Rates

    master

    Retrieve an ExchangeRate from QuickBooks using the getExchangeRate method. This method requires an options object specifying the currency details.

    Arguments:

    • options: An object containing:
      • sourcecurrencycode (required): The code for the source currency.
      • asofdate (optional): The date for which to retrieve the rate.
    • callback: Callback function called with any error and the ExchangeRate object.
  7. Delete entities from QuickBooks

    master

    Use the delete[EntityName] methods to remove records from QuickBooks. You can pass either the persistent entity object or the entity's Id. If you pass an Id, the library will automatically issue an extra GET request to retrieve the entity before attempting deletion.

    Supported entities include:

    • deleteEstimate(idOrEntity, callback)
    • deleteInvoice(idOrEntity, callback)
    • deleteJournalCode(idOrEntity, callback)
    • deleteJournalEntry(idOrEntity, callback)
    • deletePayment(idOrEntity, callback)
    • deletePurchase(idOrEntity, callback)
    • deletePurchaseOrder(idOrEntity, callback)
    • deleteRefundReceipt(idOrEntity, callback)
    • deleteSalesReceipt(idOrEntity, callback)
    • deleteTimeActivity(idOrEntity, callback)
    • deleteTransfer(idOrEntity, callback)
    • deleteVendorCredit(idOrEntity, callback)

    Arguments:

    • idOrEntity: The persistent entity object or the Id of the entity.
    • callback: A function called with (error, status), where status is the status of the persistent entity.
  8. Perform multiple operations with batch()

    master

    The batch operation allows performing multiple operations in a single request to improve efficiency.

    Supported operations:

    • create
    • update
    • delete
    • query

    Constraints:

    • The maximum number of batch items in a single request is 30.

    Arguments:

    • items: A JavaScript array of batch items.
    • callback: A function called with (error, BatchItemResponses).
  9. Update QuickBooks entities

    master

    Use the update[EntityName] methods to update existing objects in QuickBooks.

    Requirements:

    • The object passed to the method must be the persistent version of the entity, including its Id and SyncToken fields.
    • All methods use a callback(error, updatedObject) pattern.

    Special Update Behaviors:

    • Voiding Invoices, Payments, and Sales Receipts: To void an Invoice, Payment, or SalesReceipt, include void: true within the object.
    • Updating Items: The updateItem(object, callback) method accepts an optional boolean property doNotUpdateAccountOnTxns on the Item object. If set to true, it suppresses updating the income or expense account on existing transactions associated with that Item. Note: This value is compared using .toString(), so you must use the literal strings 'true' or 'false' (or boolean true/false depending on implementation context) rather than truthy/falsy integers like 1 or 0.
  10. Get or send PDF documents (Invoices, Credit Memos, Sales Receipts)

    master

    You can retrieve PDF versions of documents or email them directly to customers.

    Retrieve PDF

    Use get[DocumentType]Pdf(id, callback) to get the raw PDF data.

    • id: The Id of the persistent document.
    • callback: Called with (error, pdf).

    Methods:

    • getInvoicePdf(id, callback)
    • getCreditMemoPdf(id, callback)
    • getSalesReceiptPdf(id, callback)

    Email PDF

    Use send[DocumentType]Pdf(id, sendTo, callback) to email the document.

    • id: The Id of the persistent document.
    • sendTo (Optional): An email address. If not provided, the system uses the address found in the document's BillEmail.EmailAddress field.
    • callback: Called with (error, pdf).

    Methods:

    • sendInvoicePdf(id, sendTo, callback)
    • sendCreditMemoPdf(id, sendTo, callback)
    • sendEstimatePdf(id, sendTo, callback)
  11. Upload files as Attachables using upload()

    master

    Uploads a file as an Attachable in QuickBooks Online (QBO), with the option to link it to a specific QBO Entity.

    Arguments:

    • filename: The name of the file.
    • contentType: The MIME type of the file.
    • stream: A ReadableStream of the file contents.
    • entityType (Optional): The string name of the QBO entity the Attachable will be linked to (e.g., 'Invoice').
    • entityId (Optional): The Id of the QBO entity the Attachable will be linked to.
    • callback: A function called with (error, newlyCreatedAttachable).