stephendavidmarsh / qbdeferred

Asynchronous Quickbase API with jQuery's Deferreds
5 stars 0 forks source link

TypeError: Cannot convert undefined or null to object #2

Closed Sammyjroberts closed 7 years ago

Sammyjroberts commented 7 years ago

I had to change code in QBdef to work:

let $;
var qbDefIsNode = false
if (typeof module !== 'undefined' && module.exports) {
  qbDefIsNode = true
  var jsdom = require('jsdom');
  var fakeWindow = jsdom.jsdom().defaultView;
  $ = require('jquery')(fakeWindow);
  global.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest
  $.support.cors = true;
  global.DOMParser = require('xmldom').DOMParser
}

this was at the top of the qbdef file. Here is my code,

require('dotenv').config();
let qbdef = require('./qbdef.js')
var qbdef_test = require('./qbdeferred_test.js')

var password = process.env.QB_PASSWORD
if (!password)
    throw new Error('You must set QB_PASSWD to an appropriate Quickbase password')

let domain = new QBDomain(
    process.env.QB_DOMAIN,
    process.env.QB_USERNAME,
    password
);

var app = domain.qbApp(
    process.env.QB_DB_ID
    //, 'APPTOKEN_HERE' // Uncomment if needed
);

let desiredFields = [
    '14',  // 0 Work #
    '16',  // 1 Mobile #
    '221', // 2 Primary Phone Number
    '224', // 3 Primary Phone Type
    '222', // 4 Secondary Phone Number
    '225'  // 5 Secondary Phone Type
];
let contactsID = 'bmbkiiydm';
let contacts = app.qbTable(
    contactsID, {
        workNum: 14,
        mobileNum: 16,
        primaryNum: 221,
        primaryType: 224,
        secondaryNum: 222,
        secondaryType: 225
    }
);
contacts.query('', desiredFields)
.pipe(function(resp) {
  console.log(resp);
})
.fail(function(err) {
  console.error(err);
});

see the title for the error I get, tried to debug and got down to the _postQB function, it seems $.ajax is throwing some error, couldn't quite figure it out. I tested without qbdef, and my data was correct and the API response worked.

stephendavidmarsh commented 7 years ago

Which version of jsdom were you using?

Sammyjroberts commented 7 years ago

Latest version, I'll look up the exact number when I'm in the office later

Get Outlook for Androidhttps://aka.ms/ghei36

On Wed, Nov 16, 2016 at 12:34 PM -0800, "Stephen Marsh" notifications@github.com<mailto:notifications@github.com> wrote:

Which version of jsdom were you using?

You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/stephendavidmarsh/qbdeferred/issues/2#issuecomment-261063739, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFdoIWVzrIzKEqvx_-71g89HXonc_FC2ks5q-2jwgaJpZM4K0Z3B.

Sammyjroberts commented 7 years ago

I will retry with your package.json, somehow I didn't see it when I pulled. Used my own. Thanks for the help,

Get Outlook for Androidhttps://aka.ms/ghei36

On Wed, Nov 16, 2016 at 12:34 PM -0800, "Stephen Marsh" notifications@github.com<mailto:notifications@github.com> wrote:

Which version of jsdom were you using?

You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/stephendavidmarsh/qbdeferred/issues/2#issuecomment-261063739, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFdoIWVzrIzKEqvx_-71g89HXonc_FC2ks5q-2jwgaJpZM4K0Z3B.