0

Sparse Update Invoice

by
Published Mar 6, 2024

Sparse updating provides the ability to update a subset of properties for a given object; only elements specified in the request are updated. Missing elements are left untouched. The ID of the object to update is specified in the request body.​ [See docs here](https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/invoice#sparse-update-an-invoice)

Script quickbooks Verified

The script

Submitted by hugo697 Bun
Verified 323 days ago
1
import QuickBooks from "node-quickbooks";
2

3
type Quickbooks = {
4
  realmId: string;
5
  token: string;
6
  isSandBox: boolean;
7
};
8

9
export async function main(
10
  resource: Quickbooks,
11
  invoice: {
12
    Id?: string;
13
    sparse: boolean;
14
    DueDate?: string;
15
    Line?: any[];
16
    CustomerRef?: {
17
      value: string;
18
      name?: string;
19
    };
20
    SyncToken?: string;
21
    ShipFromAddr?: {
22
      Id?: string;
23
      PostalCode?: string;
24
      City?: string;
25
      Country?: string;
26
      Line5?: string;
27
      Line4?: string;
28
      Line3?: string;
29
      Line2?: string;
30
      Line1?: string;
31
      Lat?: string;
32
      Long?: string;
33
      CountrySubDivisionCode?: string;
34
    };
35
    CurrencyRef?: {
36
      value: string;
37
      name?: string;
38
    };
39
    DocNumber?: string;
40
    BillEmail?: {
41
      Address?: string;
42
    };
43
    TxnDate?: string;
44
    ShipDate?: {
45
      date: string;
46
    };
47
    TrackingNum?: string;
48
    ClassRef?: {
49
      value: string;
50
      name?: string;
51
    };
52
    PrintStatus?: string;
53
    SalesTermRef?: {
54
      value: string;
55
      name?: string;
56
    };
57
    TxnSource?: string;
58
    LinkedTxn?: {
59
      TxnId: string;
60
      TxnType: string;
61
      TxnLineId?: string;
62
    }[];
63
    DepositToAccountRef?: {
64
      value: string;
65
      name?: string;
66
    };
67
    GlobalTaxCalculation?: string;
68
    AllowOnlineACHPayment?: boolean;
69
    TransactionLocationType?: string;
70
    MetaData?: {
71
      CreateTime?: {
72
        dateTime: string;
73
      };
74
      LastUpdatedTime?: {
75
        dateTime: string;
76
      };
77
    };
78
    PrivateNote?: string;
79
    BillEmailCc?: {
80
      Address?: string;
81
    };
82
    CustomerMemo?: {
83
      value: string;
84
    };
85
    EmailStatus?: string;
86
    ProjectRef?: {
87
      value: string;
88
      name?: string;
89
    };
90
    ExchangeRate?: number;
91
    Deposit?: number;
92
    TxnTaxDetail?: {
93
      TxnTaxCodeRef?: {
94
        value: string;
95
        name?: string;
96
      };
97
      TotalTax?: number;
98
      TaxLine?: {
99
        DetailType: string;
100
        TaxLineDetail: {
101
          TaxRateRef: {
102
            value: string;
103
            name?: string;
104
          };
105
          NetAmountTaxable?: number;
106
          PercentBased?: boolean;
107
          TaxInclusiveAmount?: number;
108
          OverrideDeltaAmount?: number;
109
          TaxPercent?: number;
110
        };
111
        Amount?: number;
112
      }[];
113
    };
114
    ApplyTaxAfterDiscount?: boolean;
115
    HomeBalance?: number;
116
    DeliveryInfo?: {
117
      DeliveryType: string;
118
      DeliveryTime: {
119
        dateTime: string;
120
      };
121
    };
122
    TotalAmt?: number;
123
    InvoiceLink?: string;
124
    RecurDataRef?: {
125
      value: string;
126
      name?: string;
127
    };
128
    TaxExemptionRef?: {
129
      value: string;
130
      name?: string;
131
    };
132
    Balance?: number;
133
    HomeTotalAmt?: number;
134
    FreeFormAddress?: boolean;
135
    CustomField?: {
136
      DefinitionId: string;
137
      StringValue?: string;
138
      Name?: string;
139
      Type: string;
140
    }[];
141
    ShipAddr?: {
142
      Id?: string;
143
      PostalCode?: string;
144
      City?: string;
145
      Country?: string;
146
      Line5?: string;
147
      Line4?: string;
148
      Line3?: string;
149
      Line2?: string;
150
      Line1?: string;
151
      Lat?: string;
152
      Long?: string;
153
      CountrySubDivisionCode?: string;
154
    };
155
    DepartmentRef?: {
156
      value: string;
157
      name?: string;
158
    };
159
    BillEmailBcc?: {
160
      Address?: string;
161
    };
162
    ShipMethodRef?: {
163
      value: string;
164
      name?: string;
165
    };
166
    BillAddr?: {
167
      Id?: string;
168
      PostalCode?: string;
169
      City?: string;
170
      Country?: string;
171
      Line5?: string;
172
      Line4?: string;
173
      Line3?: string;
174
      Line2?: string;
175
      Line1?: string;
176
      Lat?: string;
177
      Long?: string;
178
      CountrySubDivisionCode?: string;
179
    };
180
  }
181
) {
182
  const qbo = new QuickBooks("", "", resource.token, false, resource.realmId, resource.isSandBox, true, null, "2.0");
183

184
  return new Promise((resolve, reject) => {
185
    qbo.updateInvoice(invoice, function (err: any, result: any) {
186
      if (err) {
187
        reject(err);
188
      } else {
189
        resolve(result);
190
      }
191
    });
192
  });
193
}
194