QBO Query tool
This commit is contained in:
parent
8643aebcfc
commit
cbfbcf9b06
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env node
|
||||
// qbo_query.js — Quick QBO Query Tool
|
||||
//
|
||||
// Usage:
|
||||
// node qbo_query.js invoice 110444 # By DocNumber
|
||||
// node qbo_query.js invoice-id 37973 # By QBO ID
|
||||
// node qbo_query.js payment 38733 # By Payment ID
|
||||
// node qbo_query.js query "SELECT * FROM Invoice WHERE Balance = '0' MAXRESULTS 3"
|
||||
|
||||
require('dotenv').config();
|
||||
const { makeQboApiCall, getOAuthClient } = require('./qbo_helper');
|
||||
|
||||
async function main() {
|
||||
const [type, value] = process.argv.slice(2);
|
||||
if (!type || !value) {
|
||||
console.log('Usage:\n node qbo_query.js invoice <DocNumber>\n node qbo_query.js invoice-id <QBO_ID>\n node qbo_query.js payment <Payment_ID>\n node qbo_query.js query "<QUERY>"');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const oauthClient = getOAuthClient();
|
||||
const companyId = oauthClient.getToken().realmId;
|
||||
const base = process.env.QBO_ENVIRONMENT === 'production'
|
||||
? 'https://quickbooks.api.intuit.com'
|
||||
: 'https://sandbox-quickbooks.api.intuit.com';
|
||||
|
||||
let url;
|
||||
if (type === 'invoice') {
|
||||
url = `${base}/v3/company/${companyId}/query?query=${encodeURI(`SELECT * FROM Invoice WHERE DocNumber = '${value}'`)}`;
|
||||
} else if (type === 'invoice-id') {
|
||||
url = `${base}/v3/company/${companyId}/invoice/${value}`;
|
||||
} else if (type === 'payment') {
|
||||
url = `${base}/v3/company/${companyId}/payment/${value}`;
|
||||
} else if (type === 'query') {
|
||||
url = `${base}/v3/company/${companyId}/query?query=${encodeURI(value)}`;
|
||||
} else {
|
||||
console.error('Unknown type:', type);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await makeQboApiCall({ url, method: 'GET' });
|
||||
const data = response.getJson ? response.getJson() : response.json;
|
||||
console.log(JSON.stringify(data, null, 2));
|
||||
} catch (e) {
|
||||
console.error('Error:', e.message);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Loading…
Reference in New Issue