0

I have spent hours over the last few days trying to figure out how to do a callback to get data out of a function I am importing from a node module and use it with context.res in an azure function.

I don't understand callbacks well enough to get my head around this, or I am completely off base.

module.exports = function (context, req) {

var QuickBooks = require('node-quickbooks')
var qboAuth = require('./config')
var consumerKey = qboAuth.consumerKey
var consumerSecret = qboAuth.consumerSecret
var oauthToken = qboAuth.token
var oauthTokenSecret = qboAuth.tokenSecret
var realmId = qboAuth.realmId

    var qbo = new QuickBooks(consumerKey,
                         consumerSecret,
                         oauthToken,
                         oauthTokenSecret,
                         realmId,
                         false, // use the sandbox?
                         true); // enable debugging?
                
    
    qbo.getAccount(req.query.id, function(err, account) {
            context.log(account)
            
    } );
    
context.res = {
    body: account
}
     

context.done()
}

So the context.log(account) in the qbo.getAccount() function outputs fine, however through which ever means I use I cannot get this to output to context.res = {}.

I think this is complicated by running in the Azure Function sandbox, but I am not sure.

Is someone able to point me in the right direction?

Thanks,

Dion

1 Answer 1

1

The function getAccount() should be an asynchronous function, you can move the assignment and complete function of Azure Function into the callback expression. E.G.

qbo.getAccount(req.query.id, function(err, account) {
    context.log(account);
    context.res = {
        body: account
    }
    context.done() 
    } 
);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for replying Gary, that worked! I had done that earlier and it hadn't worked, but I found just now one of my input variables had a typo since I was a bit more certain about the concept. Thanks again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.