node-quickbooks icon indicating copy to clipboard operation
node-quickbooks copied to clipboard

the client returns an empty error and no data to the callback even though the find request returns data

Open DustinAPI opened this issue 1 year ago • 0 comments

I am attempting to recreate this query with the node-quickbooks

select * from Customer Where CompanyName IN ('customer1', 'customer2')

using this code

qbo.findCustomers(
        [
          { field: 'fetchAll', value: true },
          {
            field: 'CompanyName',
            value: [adminAccounts.name, adminAccounts.locationWithContacts.name],
            operator: 'IN',
          },
        ],
        (error, customers) => {
          if (error) {
            throw new Error(JSON.stringify(error));  //error {} is thrown here
          }
 
          const quickBooksCustomer = customers.QueryResponse.Customer.find((customer) => {
            return (
              customer.CompanyName === adminAccounts.name &&
              customer.Notes.includes(adminAccounts.id)
            );
          });
...

And the terminal tells me that the data is returned.

invoking endpoint: https://sandbox-quickbooks.api.intuit.com/v3/company/xxxxxxx/query?query=select * from customer where CompanyName IN (%27customer 1671214493243%27,%27location-with-contacts 1671214494373%27) startposition 1 maxresults 1000
 
{
  "QueryResponse": {
    "Customer": [
      {
        "Taxable": true,
        "BillAddr": {
          "Id": "598",
          "Line1": "6603 Brennon Inlet",
          "City": "Oklahoma City",
          "Country": "United States of America",
          "CountrySubDivisionCode": "CT",
          "PostalCode": "99887"
        },
        "Notes": "hes.account.id:xxxxxx",
        "Job": false,
        "BillWithParent": false,
        "Balance": 0,
        "BalanceWithJobs": 42.33,
        "CurrencyRef": {
          "value": "USD",
          "name": "United States Dollar"
        },
        "PreferredDeliveryMethod": "Print",
        "domain": "QBO",
        "sparse": false,
        "Id": "241",
        "SyncToken": "0",
        "MetaData": {
          "CreateTime": "2022-12-16T10:15:03-08:00",
          "LastUpdatedTime": "2022-12-16T10:15:04-08:00"
        },
        "FullyQualifiedName": "customer 1671214493243",
        "CompanyName": "customer 1671214493243",
        "DisplayName": "customer 1671214493243",
        "PrintOnCheckName": "customer 1671214493243",
        "Active": true
      },

but the callback receives an empty object in the error parameter.


        (error, customers) => {
          if (error) {
            throw new Error(JSON.stringify(error));  //error {} is thrown here
          }


and if I ignore the error parameter, accessing the data throws an undefined error.

 
       (error, customers) => {
          if (error) {
       //     throw new Error(JSON.stringify(error));  //error {} is thrown here
          }
 
          const quickBooksCustomer = customers.QueryResponse.Customer.find((customer) => {
            return (
              customer.CompanyName === adminAccounts.name &&
              customer.Notes.includes(adminAccounts.id)
            );
          });

TypeError: Cannot read properties of undefined (reading 'Customer')

I believe https://github.com/mcohen01/node-quickbooks/issues/132 may be having a related issue.

DustinAPI avatar Dec 19 '22 21:12 DustinAPI