node-quickbooks
Version:
node.js client for Intuit's IPP QuickBooks V3 API.
1,347 lines (1,219 loc) • 104 kB
JavaScript
/**
* @file Node.js client for QuickBooks V3 API
* @name node-quickbooks
* @author Michael Cohen <michael_cohen@intuit.com>
* @license ISC
* @copyright 2014 Michael Cohen
*/
var request = require('request'),
uuid = require('uuid'),
debug = require('request-debug'),
util = require('util'),
formatISO = require('date-fns/fp/formatISO'),
_ = require('underscore'),
Promise = require('bluebird'),
version = require('./package.json').version,
xmlParser = new (require('fast-xml-parser').XMLParser)();
module.exports = QuickBooks
QuickBooks.APP_CENTER_BASE = 'https://appcenter.intuit.com';
QuickBooks.V3_ENDPOINT_BASE_URL = 'https://sandbox-quickbooks.api.intuit.com/v3/company/';
QuickBooks.QUERY_OPERATORS = ['=', 'IN', '<', '>', '<=', '>=', 'LIKE'];
QuickBooks.TOKEN_URL = 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer';
QuickBooks.REVOKE_URL = 'https://developer.api.intuit.com/v2/oauth2/tokens/revoke';
var OAUTH_ENDPOINTS = {
'1.0a': function (callback) {
callback({
REQUEST_TOKEN_URL: 'https://oauth.intuit.com/oauth/v1/get_request_token',
ACCESS_TOKEN_URL: 'https://oauth.intuit.com/oauth/v1/get_access_token',
APP_CENTER_URL: QuickBooks.APP_CENTER_BASE + '/Connect/Begin?oauth_token=',
RECONNECT_URL: QuickBooks.APP_CENTER_BASE + '/api/v1/connection/reconnect',
DISCONNECT_URL: QuickBooks.APP_CENTER_BASE + '/api/v1/connection/disconnect'
});
},
'2.0': function (callback, discoveryUrl) {
var NEW_ENDPOINT_CONFIGURATION = {};
request({
url: discoveryUrl,
headers: {
Accept: 'application/json'
}
}, function (err, res) {
if (err) {
console.log(err);
return err;
}
var json;
try {
json = JSON.parse(res.body);
} catch (error) {
console.log(error);
return error;
}
NEW_ENDPOINT_CONFIGURATION.AUTHORIZATION_URL = json.authorization_endpoint;;
NEW_ENDPOINT_CONFIGURATION.TOKEN_URL = json.token_endpoint;
NEW_ENDPOINT_CONFIGURATION.USER_INFO_URL = json.userinfo_endpoint;
NEW_ENDPOINT_CONFIGURATION.REVOKE_URL = json.revocation_endpoint;
callback(NEW_ENDPOINT_CONFIGURATION);
});
}
};
OAUTH_ENDPOINTS['1.0'] = OAUTH_ENDPOINTS['1.0a'];
/**
* Sets endpoints per OAuth version
*
* @param version - 1.0 for OAuth 1.0a, 2.0 for OAuth 2.0
* @param useSandbox - true to use the OAuth 2.0 sandbox discovery document, false (or unspecified, for backward compatibility) to use the prod discovery document.
*/
QuickBooks.setOauthVersion = function (version, useSandbox) {
version = (typeof version === 'number') ? version.toFixed(1) : version;
QuickBooks.version = version;
var discoveryUrl = useSandbox ? 'https://developer.intuit.com/.well-known/openid_sandbox_configuration/' : 'https://developer.api.intuit.com/.well-known/openid_configuration/';
OAUTH_ENDPOINTS[version](function (endpoints) {
for (var k in endpoints) {
QuickBooks[k] = endpoints[k];
}
}, discoveryUrl);
};
QuickBooks.setOauthVersion('1.0');
/**
* Node.js client encapsulating access to the QuickBooks V3 Rest API. An instance
* of this class should be instantiated on behalf of each user accessing the api.
*
* @param consumerKey - application key
* @param consumerSecret - application password
* @param token - the OAuth generated user-specific key
* @param tokenSecret - the OAuth generated user-specific password
* @param realmId - QuickBooks companyId, returned as a request parameter when the user is redirected to the provided callback URL following authentication
* @param useSandbox - boolean - See https://developer.intuit.com/v2/blog/2014/10/24/intuit-developer-now-offers-quickbooks-sandboxes
* @param debug - boolean flag to turn on logging of HTTP requests, including headers and body
* @param minorversion - integer to set minorversion in request
* @constructor
*/
function QuickBooks(consumerKey, consumerSecret, token, tokenSecret, realmId, useSandbox, debug, minorversion, oauthversion, refreshToken) {
var prefix = _.isObject(consumerKey) ? 'consumerKey.' : '';
this.consumerKey = eval(prefix + 'consumerKey');
this.consumerSecret = eval(prefix + 'consumerSecret');
this.token = eval(prefix + 'token');
this.tokenSecret = eval(prefix + 'tokenSecret');
this.realmId = eval(prefix + 'realmId');
this.useSandbox = eval(prefix + 'useSandbox');
this.debug = eval(prefix + 'debug');
this.endpoint = this.useSandbox
? QuickBooks.V3_ENDPOINT_BASE_URL
: QuickBooks.V3_ENDPOINT_BASE_URL.replace('sandbox-', '');
this.minorversion = eval(prefix + 'minorversion') || 75;
this.oauthversion = eval(prefix + 'oauthversion') || '1.0a';
this.refreshToken = eval(prefix + 'refreshToken') || null;
if (!eval(prefix + 'tokenSecret') && this.oauthversion !== '2.0') {
throw new Error('tokenSecret not defined');
}
}
/**
*
* Use the refresh token to obtain a new access token.
*
*
*/
QuickBooks.prototype.refreshAccessToken = function(callback) {
var auth = (Buffer.from(this.consumerKey + ':' + this.consumerSecret).toString('base64'));
var postBody = {
url: QuickBooks.TOKEN_URL,
headers: {
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: 'Basic ' + auth,
},
form: {
grant_type: 'refresh_token',
refresh_token: this.refreshToken
}
};
request.post(postBody, (function (e, r, data) {
if (r && r.body && r.error!=="invalid_grant") {
var refreshResponse = JSON.parse(r.body);
this.refreshToken = refreshResponse.refresh_token;
this.token = refreshResponse.access_token;
if (callback) callback(e, refreshResponse);
} else {
if (callback) callback(e, r, data);
}
}).bind(this));
};
/**
* Use either refresh token or access token to revoke access (OAuth2).
*
* @param useRefresh - boolean - Indicates which token to use: true to use the refresh token, false to use the access token.
* @param {function} callback - Callback function to call with error/response/data results.
*/
QuickBooks.prototype.revokeAccess = function(useRefresh, callback) {
var auth = (Buffer.from(this.consumerKey + ':' + this.consumerSecret).toString('base64'));
var revokeToken = useRefresh ? this.refreshToken : this.token;
var postBody = {
url: QuickBooks.REVOKE_URL,
headers: {
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: 'Basic ' + auth,
},
form: {
token: revokeToken
}
};
request.post(postBody, (function(e, r, data) {
if (r && r.statusCode === 200) {
this.refreshToken = null;
this.token = null;
this.realmId = null;
}
if (callback) callback(e, r, data);
}).bind(this));
};
/**
* Get user info (OAuth2).
*
* @param {function} callback - Callback function to call with error/response/data results.
*/
QuickBooks.prototype.getUserInfo = function(callback) {
module.request(this, 'get', {url: QuickBooks.USER_INFO_URL}, null, callback);
};
/**
* Batch operation to enable an application to perform multiple operations in a single request.
* The following batch items are supported:
create
update
delete
query
* The maximum number of batch items in a single request is 30.
*
* @param {object} items - JavaScript array of batch items
* @param {function} callback - Callback function which is called with any error and list of BatchItemResponses
*/
QuickBooks.prototype.batch = function(items, callback) {
module.request(this, 'post', {url: '/batch'}, {BatchItemRequest: items}, callback)
}
/**
* The change data capture (CDC) operation returns a list of entities that have changed since a specified time.
*
* @param {object} entities - Comma separated list or JavaScript array of entities to search for changes
* @param {object} since - JavaScript Date or string representation of the form '2012-07-20T22:25:51-07:00' to look back for changes until
* @param {function} callback - Callback function which is called with any error and list of changes
*/
QuickBooks.prototype.changeDataCapture = function(entities, since, callback) {
var url = '/cdc?entities='
url += typeof entities === 'string' ? entities : entities.join(',')
url += '&changedSince='
url += typeof since === 'string' ? since : formatISO(since)
module.request(this, 'get', {url: url}, null, callback)
}
/**
* Uploads a file as an Attachable in QBO, optionally linking it to the specified
* QBO Entity.
*
* @param {string} filename - the name of the file
* @param {string} contentType - the mime type of the file
* @param {object} stream - ReadableStream of file contents
* @param {object} entityType - optional string name of the QBO entity the Attachable will be linked to (e.g. Invoice)
* @param {object} entityId - optional Id of the QBO entity the Attachable will be linked to
* @param {function} callback - callback which receives the newly created Attachable
*/
QuickBooks.prototype.upload = function(filename, contentType, stream, entityType, entityId, callback) {
var that = this
var opts = {
url: '/upload',
formData: {
file_content_01: {
value: stream,
options: {
filename: filename,
contentType: contentType
}
}
}
}
module.request(this, 'post', opts, null, module.unwrap(function(err, data) {
if (err || data[0].Fault) {
(callback || entityType)(err || data[0], null)
} else if (_.isFunction(entityType)) {
entityType(null, data[0].Attachable)
} else {
var id = data[0].Attachable.Id
that.updateAttachable({
Id: id,
SyncToken: '0',
AttachableRef: [{
EntityRef: {
type: entityType,
value: entityId + ''
}
}]
}, function(err, data) {
callback(err, data)
})
}
}, 'AttachableResponse'))
}
/**
* Creates the Account in QuickBooks
*
* @param {object} account - The unsaved account, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Account
*/
QuickBooks.prototype.createAccount = function(account, callback) {
module.create(this, 'account', account, callback)
}
/**
* Creates the Attachable in QuickBooks
*
* @param {object} attachable - The unsaved attachable, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Attachable
*/
QuickBooks.prototype.createAttachable = function(attachable, callback) {
module.create(this, 'attachable', attachable, callback)
}
/**
* Creates the Bill in QuickBooks
*
* @param {object} bill - The unsaved bill, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Bill
*/
QuickBooks.prototype.createBill = function(bill, callback) {
module.create(this, 'bill', bill, callback)
}
/**
* Creates the BillPayment in QuickBooks
*
* @param {object} billPayment - The unsaved billPayment, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent BillPayment
*/
QuickBooks.prototype.createBillPayment = function(billPayment, callback) {
module.create(this, 'billPayment', billPayment, callback)
}
/**
* Creates the Class in QuickBooks
*
* @param {object} class - The unsaved class, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Class
*/
QuickBooks.prototype.createClass = function(klass, callback) {
module.create(this, 'class', klass, callback)
}
/**
* Creates the CreditMemo in QuickBooks
*
* @param {object} creditMemo - The unsaved creditMemo, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent CreditMemo
*/
QuickBooks.prototype.createCreditMemo = function(creditMemo, callback) {
module.create(this, 'creditMemo', creditMemo, callback)
}
/**
* Creates the Customer in QuickBooks
*
* @param {object} customer - The unsaved customer, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Customer
*/
QuickBooks.prototype.createCustomer = function(customer, callback) {
module.create(this, 'customer', customer, callback)
}
/**
* Creates the Department in QuickBooks
*
* @param {object} department - The unsaved department, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Department
*/
QuickBooks.prototype.createDepartment = function(department, callback) {
module.create(this, 'department', department, callback)
}
/**
* Creates the Deposit in QuickBooks
*
* @param {object} deposit - The unsaved Deposit, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Deposit
*/
QuickBooks.prototype.createDeposit = function(deposit, callback) {
module.create(this, 'deposit', deposit, callback)
}
/**
* Creates the Employee in QuickBooks
*
* @param {object} employee - The unsaved employee, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Employee
*/
QuickBooks.prototype.createEmployee = function(employee, callback) {
module.create(this, 'employee', employee, callback)
}
/**
* Creates the Estimate in QuickBooks
*
* @param {object} estimate - The unsaved estimate, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Estimate
*/
QuickBooks.prototype.createEstimate = function(estimate, callback) {
module.create(this, 'estimate', estimate, callback)
}
/**
* Creates the Invoice in QuickBooks
*
* @param {object} invoice - The unsaved invoice, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Invoice
*/
QuickBooks.prototype.createInvoice = function(invoice, callback) {
module.create(this, 'invoice', invoice, callback)
}
/**
* Creates the Item in QuickBooks
*
* @param {object} item - The unsaved item, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Item
*/
QuickBooks.prototype.createItem = function(item, callback) {
module.create(this, 'item', item, callback)
}
/**
* Creates the JournalCode in QuickBooks
*
* @param {object} journalCode - The unsaved journalCode, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent JournalCode
*/
QuickBooks.prototype.createJournalCode = function(journalCode, callback) {
module.create(this, 'journalCode', journalCode, callback)
}
/**
* Creates the JournalEntry in QuickBooks
*
* @param {object} journalEntry - The unsaved journalEntry, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent JournalEntry
*/
QuickBooks.prototype.createJournalEntry = function(journalEntry, callback) {
module.create(this, 'journalEntry', journalEntry, callback)
}
/**
* Creates the Payment in QuickBooks
*
* @param {object} payment - The unsaved payment, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Payment
*/
QuickBooks.prototype.createPayment = function(payment, callback) {
module.create(this, 'payment', payment, callback)
}
/**
* Creates the PaymentMethod in QuickBooks
*
* @param {object} paymentMethod - The unsaved paymentMethod, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent PaymentMethod
*/
QuickBooks.prototype.createPaymentMethod = function(paymentMethod, callback) {
module.create(this, 'paymentMethod', paymentMethod, callback)
}
/**
* Creates the Purchase in QuickBooks
*
* @param {object} purchase - The unsaved purchase, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Purchase
*/
QuickBooks.prototype.createPurchase = function(purchase, callback) {
module.create(this, 'purchase', purchase, callback)
}
/**
* Creates the PurchaseOrder in QuickBooks
*
* @param {object} purchaseOrder - The unsaved purchaseOrder, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent PurchaseOrder
*/
QuickBooks.prototype.createPurchaseOrder = function(purchaseOrder, callback) {
module.create(this, 'purchaseOrder', purchaseOrder, callback)
}
/**
* Creates the RefundReceipt in QuickBooks
*
* @param {object} refundReceipt - The unsaved refundReceipt, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent RefundReceipt
*/
QuickBooks.prototype.createRefundReceipt = function(refundReceipt, callback) {
module.create(this, 'refundReceipt', refundReceipt, callback)
}
/**
* Creates the SalesReceipt in QuickBooks
*
* @param {object} salesReceipt - The unsaved salesReceipt, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent SalesReceipt
*/
QuickBooks.prototype.createSalesReceipt = function(salesReceipt, callback) {
module.create(this, 'salesReceipt', salesReceipt, callback)
}
/**
* Creates the TaxAgency in QuickBooks
*
* @param {object} taxAgency - The unsaved taxAgency, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent TaxAgency
*/
QuickBooks.prototype.createTaxAgency = function(taxAgency, callback) {
module.create(this, 'taxAgency', taxAgency, callback)
}
/**
* Creates the TaxService in QuickBooks
*
* @param {object} taxService - The unsaved taxService, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent TaxService
*/
QuickBooks.prototype.createTaxService = function(taxService, callback) {
module.create(this, 'taxService/taxcode', taxService, callback)
}
/**
* Creates the Term in QuickBooks
*
* @param {object} term - The unsaved term, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Term
*/
QuickBooks.prototype.createTerm = function(term, callback) {
module.create(this, 'term', term, callback)
}
/**
* Creates the TimeActivity in QuickBooks
*
* @param {object} timeActivity - The unsaved timeActivity, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent TimeActivity
*/
QuickBooks.prototype.createTimeActivity = function(timeActivity, callback) {
module.create(this, 'timeActivity', timeActivity, callback)
}
/**
* Creates the Transfer in QuickBooks
*
* @param {object} transfer - The unsaved Transfer, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Transfer
*/
QuickBooks.prototype.createTransfer = function(transfer, callback) {
module.create(this, 'transfer', transfer, callback)
}
/**
* Creates the Vendor in QuickBooks
*
* @param {object} vendor - The unsaved vendor, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Vendor
*/
QuickBooks.prototype.createVendor = function(vendor, callback) {
module.create(this, 'vendor', vendor, callback)
}
/**
* Creates the VendorCredit in QuickBooks
*
* @param {object} vendorCredit - The unsaved vendorCredit, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent VendorCredit
*/
QuickBooks.prototype.createVendorCredit = function(vendorCredit, callback) {
module.create(this, 'vendorCredit', vendorCredit, callback)
}
/**
* Retrieves the Account from QuickBooks
*
* @param {string} Id - The Id of persistent Account
* @param {function} callback - Callback function which is called with any error and the persistent Account
*/
QuickBooks.prototype.getAccount = function(id, callback) {
module.read(this, 'account', id, callback)
}
/**
* Retrieves the Attachable from QuickBooks
*
* @param {string} Id - The Id of persistent Attachable
* @param {function} callback - Callback function which is called with any error and the persistent Attachable
*/
QuickBooks.prototype.getAttachable = function(id, callback) {
module.read(this, 'attachable', id, callback)
}
/**
* Retrieves the Bill from QuickBooks
*
* @param {string} Id - The Id of persistent Bill
* @param {function} callback - Callback function which is called with any error and the persistent Bill
*/
QuickBooks.prototype.getBill = function(id, callback) {
module.read(this, 'bill', id, callback)
}
/**
* Retrieves the BillPayment from QuickBooks
*
* @param {string} Id - The Id of persistent BillPayment
* @param {function} callback - Callback function which is called with any error and the persistent BillPayment
*/
QuickBooks.prototype.getBillPayment = function(id, callback) {
module.read(this, 'billPayment', id, callback)
}
/**
* Retrieves the Class from QuickBooks
*
* @param {string} Id - The Id of persistent Class
* @param {function} callback - Callback function which is called with any error and the persistent Class
*/
QuickBooks.prototype.getClass = function(id, callback) {
module.read(this, 'class', id, callback)
}
/**
* Retrieves the CompanyInfo from QuickBooks
*
* @param {string} Id - The Id of persistent CompanyInfo
* @param {function} callback - Callback function which is called with any error and the persistent CompanyInfo
*/
QuickBooks.prototype.getCompanyInfo = function(id, callback) {
module.read(this, 'companyInfo', id, callback)
}
/**
* Retrieves the CompanyCurrency from QuickBooks
*
* @param {string} Id - The Id of persistent CompanyCurrency
* @param {function} callback - Callback function which is called with any error and the persistent CompanyCurrency
*/
QuickBooks.prototype.getCompanyCurrency = function(id, callback) {
module.read(this, 'companyCurrency', id, callback)
}
/**
* Retrieves the CreditMemo from QuickBooks
*
* @param {string} Id - The Id of persistent CreditMemo
* @param {function} callback - Callback function which is called with any error and the persistent CreditMemo
*/
QuickBooks.prototype.getCreditMemo = function(id, callback) {
module.read(this, 'creditMemo', id, callback)
}
/**
* Retrieves the Customer from QuickBooks
*
* @param {string} Id - The Id of persistent Customer
* @param {function} callback - Callback function which is called with any error and the persistent Customer
*/
QuickBooks.prototype.getCustomer = function(id, callback) {
module.read(this, 'customer', id, callback)
}
/**
* Retrieves the CustomerType from QuickBooks
*
* @param {string} Id - The Id of persistent CustomerType
* @param {function} callback - Callback function which is called with any error and the persistent CustomerType
*/
QuickBooks.prototype.getCustomerType = function(id, callback) {
module.read(this, 'customerType', id, callback)
}
/**
* Retrieves the Department from QuickBooks
*
* @param {string} Id - The Id of persistent Department
* @param {function} callback - Callback function which is called with any error and the persistent Department
*/
QuickBooks.prototype.getDepartment = function(id, callback) {
module.read(this, 'department', id, callback)
}
/**
* Retrieves the Deposit from QuickBooks
*
* @param {string} Id - The Id of persistent Deposit
* @param {function} callback - Callback function which is called with any error and the persistent Deposit
*/
QuickBooks.prototype.getDeposit = function(id, callback) {
module.read(this, 'deposit', id, callback)
}
/**
* Retrieves the Employee from QuickBooks
*
* @param {string} Id - The Id of persistent Employee
* @param {function} callback - Callback function which is called with any error and the persistent Employee
*/
QuickBooks.prototype.getEmployee = function(id, callback) {
module.read(this, 'employee', id, callback)
}
/**
* Retrieves the Estimate from QuickBooks
*
* @param {string} Id - The Id of persistent Estimate
* @param {function} callback - Callback function which is called with any error and the persistent Estimate
*/
QuickBooks.prototype.getEstimate = function(id, callback) {
module.read(this, 'estimate', id, callback)
}
/**
* Retrieves an ExchangeRate from QuickBooks
*
* @param {object} options - An object with options including the required `sourcecurrencycode` parameter and optional `asofdate` parameter.
* @param {function} callback - Callback function which is called with any error and the ExchangeRate
*/
QuickBooks.prototype.getExchangeRate = function(options, callback) {
var url = "/exchangerate";
module.request(this, 'get', {url: url, qs: options}, null, callback)
}
/**
* Retrieves the Estimate PDF from QuickBooks
*
* @param {string} Id - The Id of persistent Estimate
* @param {function} callback - Callback function which is called with any error and the Estimate PDF
*/
QuickBooks.prototype.getEstimatePdf = function(id, callback) {
module.read(this, 'Estimate', id + '/pdf', callback)
};
/**
* Emails the Estimate PDF from QuickBooks to the address supplied in Estimate.BillEmail.EmailAddress
* or the specified 'sendTo' address
*
* @param {string} Id - The Id of persistent Estimate
* @param {string} sendTo - optional email address to send the PDF to. If not provided, address supplied in Estimate.BillEmail.EmailAddress will be used
* @param {function} callback - Callback function which is called with any error and the Estimate PDF
*/
QuickBooks.prototype.sendEstimatePdf = function(id, sendTo, callback) {
var path = '/estimate/' + id + '/send'
callback = _.isFunction(sendTo) ? sendTo : callback
if (sendTo && ! _.isFunction(sendTo)) {
path += '?sendTo=' + sendTo
}
module.request(this, 'post', {url: path}, null, module.unwrap(callback, 'Estimate'))
}
/**
* Retrieves the Invoice from QuickBooks
*
* @param {string} Id - The Id of persistent Invoice
* @param {function} callback - Callback function which is called with any error and the persistent Invoice
*/
QuickBooks.prototype.getInvoice = function(id, callback) {
module.read(this, 'invoice', id, callback)
}
/**
* Retrieves the Invoice PDF from QuickBooks
*
* @param {string} Id - The Id of persistent Invoice
* @param {function} callback - Callback function which is called with any error and the Invoice PDF
*/
QuickBooks.prototype.getInvoicePdf = function(id, callback) {
module.read(this, 'Invoice', id + '/pdf', callback)
}
/**
* Emails the Invoice PDF from QuickBooks to the address supplied in Invoice.BillEmail.EmailAddress
* or the specified 'sendTo' address
*
* @param {string} Id - The Id of persistent Invoice
* @param {string} sendTo - optional email address to send the PDF to. If not provided, address supplied in Invoice.BillEmail.EmailAddress will be used
* @param {function} callback - Callback function which is called with any error and the Invoice PDF
*/
QuickBooks.prototype.sendInvoicePdf = function(id, sendTo, callback) {
var path = '/invoice/' + id + '/send'
callback = _.isFunction(sendTo) ? sendTo : callback
if (sendTo && ! _.isFunction(sendTo)) {
path += '?sendTo=' + sendTo
}
module.request(this, 'post', {url: path}, null, module.unwrap(callback, 'Invoice'))
}
/**
* Retrieves the Credit Memo PDF from QuickBooks
*
* @param {string} Id - The Id of persistent Credit Memo
* @param {function} callback - Callback function which is called with any error and the Credit Memo PDF
*/
QuickBooks.prototype.getCreditMemoPdf = function(id, callback) {
module.read(this, 'CreditMemo', id + '/pdf', callback)
}
/**
* Emails the Credit Memo PDF from QuickBooks to the address supplied in CreditMemo.BillEmail.EmailAddress
* or the specified 'sendTo' address
*
* @param {string} Id - The Id of persistent Credit Memo
* @param {string} sendTo - optional email address to send the PDF to. If not provided, address supplied in CreditMemo.BillEmail.EmailAddress will be used
* @param {function} callback - Callback function which is called with any error and the Credit Memo PDF
*/
QuickBooks.prototype.sendCreditMemoPdf = function(id, sendTo, callback) {
var path = '/creditmemo/' + id + '/send'
callback = _.isFunction(sendTo) ? sendTo : callback
if (sendTo && ! _.isFunction(sendTo)) {
path += '?sendTo=' + sendTo
}
module.request(this, 'post', {url: path}, null, module.unwrap(callback, 'CreditMemo'))
}
/**
* Emails the Purchase Order from QuickBooks to the address supplied in PurchaseOrder.POEmail.Address
* or the specified 'sendTo' address
*
* @param {string} Id - The Id of persistent Purchase Order
* @param {string} sendTo - optional email address to send the PDF to. If not provided, address supplied in PurchaseOrder.POEmail.Address will be used
* @param {function} callback - Callback function which is called with any error and the Invoice PDF
*/
QuickBooks.prototype.sendPurchaseOrder = function(id, sendTo, callback) {
var path = '/purchaseorder/' + id + '/send'
callback = _.isFunction(sendTo) ? sendTo : callback
if (sendTo && ! _.isFunction(sendTo)) {
path += '?sendTo=' + sendTo
}
module.request(this, 'post', {url: path}, null, module.unwrap(callback, 'PurchaseOrder'))
}
/**
* Retrieves the Item from QuickBooks
*
* @param {string} Id - The Id of persistent Item
* @param {function} callback - Callback function which is called with any error and the persistent Item
*/
QuickBooks.prototype.getItem = function(id, callback) {
module.read(this, 'item', id, callback)
}
/**
* Retrieves the JournalCode from QuickBooks
*
* @param {string} Id - The Id of persistent JournalCode
* @param {function} callback - Callback function which is called with any error and the persistent JournalCode
*/
QuickBooks.prototype.getJournalCode = function(id, callback) {
module.read(this, 'journalCode', id, callback)
}
/**
* Retrieves the JournalEntry from QuickBooks
*
* @param {string} Id - The Id of persistent JournalEntry
* @param {function} callback - Callback function which is called with any error and the persistent JournalEntry
*/
QuickBooks.prototype.getJournalEntry = function(id, callback) {
module.read(this, 'journalEntry', id, callback)
}
/**
* Retrieves the Payment from QuickBooks
*
* @param {string} Id - The Id of persistent Payment
* @param {function} callback - Callback function which is called with any error and the persistent Payment
*/
QuickBooks.prototype.getPayment = function(id, callback) {
module.read(this, 'payment', id, callback)
}
/**
* Retrieves the PaymentMethod from QuickBooks
*
* @param {string} Id - The Id of persistent PaymentMethod
* @param {function} callback - Callback function which is called with any error and the persistent PaymentMethod
*/
QuickBooks.prototype.getPaymentMethod = function(id, callback) {
module.read(this, 'paymentMethod', id, callback)
}
/**
* Retrieves the Preferences from QuickBooks
*
* @param {function} callback - Callback function which is called with any error and the persistent Preferences
*/
QuickBooks.prototype.getPreferences = function(callback) {
module.read(this, 'preferences', null, callback)
}
/**
* Retrieves the Purchase from QuickBooks
*
* @param {string} Id - The Id of persistent Purchase
* @param {function} callback - Callback function which is called with any error and the persistent Purchase
*/
QuickBooks.prototype.getPurchase = function(id, callback) {
module.read(this, 'purchase', id, callback)
}
/**
* Retrieves the PurchaseOrder from QuickBooks
*
* @param {string} Id - The Id of persistent PurchaseOrder
* @param {function} callback - Callback function which is called with any error and the persistent PurchaseOrder
*/
QuickBooks.prototype.getPurchaseOrder = function(id, callback) {
module.read(this, 'purchaseOrder', id, callback)
}
/**
* Retrieves the RefundReceipt from QuickBooks
*
* @param {string} Id - The Id of persistent RefundReceipt
* @param {function} callback - Callback function which is called with any error and the persistent RefundReceipt
*/
QuickBooks.prototype.getRefundReceipt = function(id, callback) {
module.read(this, 'refundReceipt', id, callback)
}
/**
* Retrieves the Reports from QuickBooks
*
* @param {string} Id - The Id of persistent Reports
* @param {function} callback - Callback function which is called with any error and the persistent Reports
*/
QuickBooks.prototype.getReports = function(id, callback) {
module.read(this, 'reports', id, callback)
}
/**
* Retrieves the SalesReceipt from QuickBooks
*
* @param {string} Id - The Id of persistent SalesReceipt
* @param {function} callback - Callback function which is called with any error and the persistent SalesReceipt
*/
QuickBooks.prototype.getSalesReceipt = function(id, callback) {
module.read(this, 'salesReceipt', id, callback)
}
/**
* Retrieves the SalesReceipt PDF from QuickBooks
*
* @param {string} Id - The Id of persistent SalesReceipt
* @param {function} callback - Callback function which is called with any error and the SalesReceipt PDF
*/
QuickBooks.prototype.getSalesReceiptPdf = function(id, callback) {
module.read(this, 'salesReceipt', id + '/pdf', callback)
}
/**
* Emails the SalesReceipt PDF from QuickBooks to the address supplied in SalesReceipt.BillEmail.EmailAddress
* or the specified 'sendTo' address
*
* @param {string} Id - The Id of persistent SalesReceipt
* @param {string} sendTo - optional email address to send the PDF to. If not provided, address supplied in SalesReceipt.BillEmail.EmailAddress will be used
* @param {function} callback - Callback function which is called with any error and the SalesReceipt PDF
*/
QuickBooks.prototype.sendSalesReceiptPdf = function(id, sendTo, callback) {
var path = '/salesreceipt/' + id + '/send'
callback = _.isFunction(sendTo) ? sendTo : callback
if (sendTo && ! _.isFunction(sendTo)) {
path += '?sendTo=' + sendTo
}
module.request(this, 'post', {url: path}, null, module.unwrap(callback, 'SalesReceipt'))
}
/**
* Retrieves the TaxAgency from QuickBooks
*
* @param {string} Id - The Id of persistent TaxAgency
* @param {function} callback - Callback function which is called with any error and the persistent TaxAgency
*/
QuickBooks.prototype.getTaxAgency = function(id, callback) {
module.read(this, 'taxAgency', id, callback)
}
/**
* Retrieves the TaxCode from QuickBooks
*
* @param {string} Id - The Id of persistent TaxCode
* @param {function} callback - Callback function which is called with any error and the persistent TaxCode
*/
QuickBooks.prototype.getTaxCode = function(id, callback) {
module.read(this, 'taxCode', id, callback)
}
/**
* Retrieves the TaxRate from QuickBooks
*
* @param {string} Id - The Id of persistent TaxRate
* @param {function} callback - Callback function which is called with any error and the persistent TaxRate
*/
QuickBooks.prototype.getTaxRate = function(id, callback) {
module.read(this, 'taxRate', id, callback)
}
/**
* Retrieves the Term from QuickBooks
*
* @param {string} Id - The Id of persistent Term
* @param {function} callback - Callback function which is called with any error and the persistent Term
*/
QuickBooks.prototype.getTerm = function(id, callback) {
module.read(this, 'term', id, callback)
}
/**
* Retrieves the TimeActivity from QuickBooks
*
* @param {string} Id - The Id of persistent TimeActivity
* @param {function} callback - Callback function which is called with any error and the persistent TimeActivity
*/
QuickBooks.prototype.getTimeActivity = function(id, callback) {
module.read(this, 'timeActivity', id, callback)
}
/**
* Retrieves the Transfer from QuickBooks
*
* @param {string} Id - The Id of persistent Term
* @param {function} callback - Callback function which is called with any error and the persistent Transfer
*/
QuickBooks.prototype.getTransfer = function(id, callback) {
module.read(this, 'transfer', id, callback)
}
/**
* Retrieves the Vendor from QuickBooks
*
* @param {string} Id - The Id of persistent Vendor
* @param {function} callback - Callback function which is called with any error and the persistent Vendor
*/
QuickBooks.prototype.getVendor = function(id, callback) {
module.read(this, 'vendor', id, callback)
}
/**
* Retrieves the VendorCredit from QuickBooks
*
* @param {string} Id - The Id of persistent VendorCredit
* @param {function} callback - Callback function which is called with any error and the persistent VendorCredit
*/
QuickBooks.prototype.getVendorCredit = function(id, callback) {
module.read(this, 'vendorCredit', id, callback)
}
/**
* Updates QuickBooks version of Account
*
* @param {object} account - The persistent Account, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Account
*/
QuickBooks.prototype.updateAccount = function(account, callback) {
module.update(this, 'account', account, callback)
}
/**
* Updates QuickBooks version of Attachable
*
* @param {object} attachable - The persistent Attachable, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Attachable
*/
QuickBooks.prototype.updateAttachable = function(attachable, callback) {
module.update(this, 'attachable', attachable, callback)
}
/**
* Updates QuickBooks version of Bill
*
* @param {object} bill - The persistent Bill, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Bill
*/
QuickBooks.prototype.updateBill = function(bill, callback) {
module.update(this, 'bill', bill, callback)
}
/**
* Updates QuickBooks version of BillPayment
*
* @param {object} billPayment - The persistent BillPayment, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent BillPayment
*/
QuickBooks.prototype.updateBillPayment = function(billPayment, callback) {
module.update(this, 'billPayment', billPayment, callback)
}
/**
* Updates QuickBooks version of Class
*
* @param {object} class - The persistent Class, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Class
*/
QuickBooks.prototype.updateClass = function(klass, callback) {
module.update(this, 'class', klass, callback)
}
/**
* Updates QuickBooks version of CompanyInfo
*
* @param {object} companyInfo - The persistent CompanyInfo, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent CompanyInfo
*/
QuickBooks.prototype.updateCompanyInfo = function(companyInfo, callback) {
module.update(this, 'companyInfo', companyInfo, callback)
}
/**
* Updates QuickBooks version of CreditMemo
*
* @param {object} creditMemo - The persistent CreditMemo, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent CreditMemo
*/
QuickBooks.prototype.updateCreditMemo = function(creditMemo, callback) {
module.update(this, 'creditMemo', creditMemo, callback)
}
/**
* Updates QuickBooks version of Customer
*
* @param {object} customer - The persistent Customer, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Customer
*/
QuickBooks.prototype.updateCustomer = function(customer, callback) {
module.update(this, 'customer', customer, callback)
}
/**
* Updates QuickBooks version of Department
*
* @param {object} department - The persistent Department, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Department
*/
QuickBooks.prototype.updateDepartment = function(department, callback) {
module.update(this, 'department', department, callback)
}
/**
* Updates QuickBooks version of Deposit
*
* @param {object} deposit - The persistent Deposit, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Deposit
*/
QuickBooks.prototype.updateDeposit = function(deposit, callback) {
module.update(this, 'deposit', deposit, callback)
}
/**
* Updates QuickBooks version of Employee
*
* @param {object} employee - The persistent Employee, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Employee
*/
QuickBooks.prototype.updateEmployee = function(employee, callback) {
module.update(this, 'employee', employee, callback)
}
/**
* Updates QuickBooks version of Estimate
*
* @param {object} estimate - The persistent Estimate, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Estimate
*/
QuickBooks.prototype.updateEstimate = function(estimate, callback) {
module.update(this, 'estimate', estimate, callback)
}
/**
* Updates QuickBooks version of Invoice
*
* @param {object} invoice - The persistent Invoice, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Invoice
*/
QuickBooks.prototype.updateInvoice = function(invoice, callback) {
module.update(this, 'invoice', invoice, callback)
}
/**
* Updates QuickBooks version of Item
*
* @param {object} item - The persistent Item, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Item
*/
QuickBooks.prototype.updateItem = function(item, callback) {
var opts = {};
if (item.doNotUpdateAccountOnTxns && item.doNotUpdateAccountOnTxns.toString() === 'true') {
opts.qs = { include: 'donotupdateaccountontxns' }
delete item.doNotUpdateAccountOnTxns
}
module.update(this, 'item', item, callback, opts)
}
/**
* Updates QuickBooks version of JournalCode
*
* @param {object} journalCode - The persistent JournalCode, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent JournalCode
*/
QuickBooks.prototype.updateJournalCode = function(journalCode, callback) {
module.update(this, 'journalCode', journalCode, callback)
}
/**
* Updates QuickBooks version of JournalEntry
*
* @param {object} journalEntry - The persistent JournalEntry, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent JournalEntry
*/
QuickBooks.prototype.updateJournalEntry = function(journalEntry, callback) {
module.update(this, 'journalEntry', journalEntry, callback)
}
/**
* Updates QuickBooks version of Payment
*
* @param {object} payment - The persistent Payment, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Payment
*/
QuickBooks.prototype.updatePayment = function(payment, callback) {
module.update(this, 'payment', payment, callback)
}
/**
* Updates QuickBooks version of PaymentMethod
*
* @param {object} paymentMethod - The persistent PaymentMethod, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent PaymentMethod
*/
QuickBooks.prototype.updatePaymentMethod = function(paymentMethod, callback) {
module.update(this, 'paymentMethod', paymentMethod, callback)
}
/**
* Updates QuickBooks version of Preferences
*
* @param {object} preferences - The persistent Preferences, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Preferences
*/
QuickBooks.prototype.updatePreferences = function(preferences, callback) {
module.update(this, 'preferences', preferences, callback)
}
/**
* Updates QuickBooks version of Purchase
*
* @param {object} purchase - The persistent Purchase, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Purchase
*/
QuickBooks.prototype.updatePurchase = function(purchase, callback) {
module.update(this, 'purchase', purchase, callback)
}
/**
* Updates QuickBooks version of PurchaseOrder
*
* @param {object} purchaseOrder - The persistent PurchaseOrder, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent PurchaseOrder
*/
QuickBooks.prototype.updatePurchaseOrder = function(purchaseOrder, callback) {
module.update(this, 'purchaseOrder', purchaseOrder, callback)
}
/**
* Updates QuickBooks version of RefundReceipt
*
* @param {object} refundReceipt - The persistent RefundReceipt, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent RefundReceipt
*/
QuickBooks.prototype.updateRefundReceipt = function(refundReceipt, callback) {
module.update(this, 'refundReceipt', refundReceipt, callback)
}
/**
* Updates QuickBooks version of SalesReceipt
*
* @param {object} salesReceipt - The persistent SalesReceipt, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent SalesReceipt
*/
QuickBooks.prototype.updateSalesReceipt = function(salesReceipt, callback) {
module.update(this, 'salesReceipt', salesReceipt, callback)
}
/**
* Updates QuickBooks version of TaxAgency
*
* @param {object} taxAgency - The persistent TaxAgency, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent TaxAgency
*/
QuickBooks.prototype.updateTaxAgency = function(taxAgency, callback) {
module.update(this, 'taxAgency', taxAgency, callback)
}
/**
* Updates QuickBooks version of TaxCode
*
* @param {object} taxCode - The persistent TaxCode, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent TaxCode
*/
QuickBooks.prototype.updateTaxCode = function(taxCode, callback) {
module.update(this, 'taxCode', taxCode, callback)
}
/**
* Updates QuickBooks version of TaxRate
*
* @param {object} taxRate - The persistent TaxRate, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent TaxRate
*/
QuickBooks.prototype.updateTaxRate = function(taxRate, callback) {
module.update(this, 'taxRate', taxRate, callback)
}
/**
* Updates QuickBooks version of Term
*
* @param {object} term - The persistent Term, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Term
*/
QuickBooks.prototype.updateTerm = function(term, callback) {
module.update(this, 'term', term, callback)
}
/**
* Updates QuickBooks version of TimeActivity
*
* @param {object} timeActivity - The persistent TimeActivity, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent TimeActivity
*/
QuickBooks.prototype.updateTimeActivity = function(timeActivity, callback) {
module.update(this, 'timeActivity', timeActivity, callback)
}
/**
* Updates QuickBooks version of Transfer
*
* @param {object} Transfer - The persistent Transfer, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Transfer
*/
QuickBooks.prototype.updateTransfer = function(transfer, callback) {
module.update(this, 'transfer', transfer, callback)
}
/**
* Updates QuickBooks version of Vendor
*
* @param {object} vendor - The persistent Vendor, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent Vendor
*/
QuickBooks.prototype.updateVendor = function(vendor, callback) {
module.update(this, 'vendor', vendor, callback)
}
/**
* Updates QuickBooks version of VendorCredit
*
* @param {object} vendorCredit - The persistent VendorCredit, including Id and SyncToken fields
* @param {function} callback - Callback function which is called with any error and the persistent VendorCredit
*/
QuickBooks.prototype.updateVendorCredit = functio