You can construct a promise based on a qbo3 API call as follows:
qbo3.getPromise = function(cn, method, data) {
return new Promise(function(resolve, reject) {
new (qbo3[cn] || qbo3[cn + 'Object'])().invokeJson(method, data, { success: resolve, error: reject });
})
}
where:
cn
: is the className of the API endpoint (e.g. Process
, Loan
, Person
, Message
, etc.)
method
: is the class method to be invoked (e.g. Select
, Search
, Update
, etc.)
data
: is the JSON
data to be submitted
The (qbo3[cn] || qbo3[cn + 'Object'])
expression is just a bit of sugar to allow you to pass either Process
or ProcessObject
as the cn
parameter to qbo3.getPromise(...)
.
Then you can use:
var data = {...}
var myPromise = qbo3.getPromise('Process', 'StartRecordingTime', data)
.then(return qbo3.getPromise('Process', 'RealWorldApiCall', data))
.then(return qbo3.getPromise('Process', 'EndRecordingTime', {}))
More generic usage leveraging the results of one API for the data being passed to a subsequent call:
var somePromise = qbo3.getPromise('Person', 'Search', {"Person": "someuser@acme.com"})
.then(json => {
const id = json.PersonCollection.PersonItem[0].PersonID;
return qbo3.getPromise('ProcessObject', 'Search', { "CreatedPersonID": id })
}).then(processes => console.log(processes));
Note that if you're just troubleshooting response times, qbo3
includes an X-Execution-Time
response header all API calls. This header is not passed to the resolve
method, you can inspect it from Chrome's developer console's Network
table, pictured here:
