0

Create Purchase

by
Published Jun 6, 2022

Creates a new purchase. [See docs here](https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/purchase#create-a-purchase)

Script quickbooks Verified

The script

Submitted by hugo697 Bun
Verified 324 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
  purchase: {
12
    PaymentType: string;
13
    AccountRef: {
14
      value: string;
15
      name?: string;
16
    };
17
    Line: {
18
      Id?: string;
19
      DetailType: string;
20
      Amount: number;
21
      AccountBasedExpenseLineDetail: {
22
        AccountRef: {
23
          value: string;
24
          name?: string;
25
        };
26
        ProjectRef?: {
27
          value: string;
28
        };
29
        TaxAmount?: number;
30
        TaxInclusiveAmt?: number;
31
        ClassRef?: {
32
          value: string;
33
          name?: string;
34
        };
35
        TaxCodeRef?: {
36
          value: string;
37
          name?: string;
38
        };
39
        MarkupInfo?: {
40
          PriceLevelRef?: {
41
            value: string;
42
            name?: string;
43
          };
44
          Percent?: number;
45
          MarkUpIncomeAccountRef?: {
46
            value: string;
47
            name?: string;
48
          };
49
        };
50
        BillableStatus?: string;
51
        CustomerRef?: {
52
          value: string;
53
          name?: string;
54
        };
55
      };
56
      Description?: string;
57
      LineNum?: number;
58
    }[];
59
    CurrencyRef?: {
60
      value: string;
61
      name?: string;
62
    };
63
  }
64
) {
65
  const qbo = new QuickBooks("", "", resource.token, false, resource.realmId, resource.isSandBox, true, null, "2.0");
66

67
  return new Promise((resolve, reject) => {
68
    qbo.createPurchase(purchase, function (err: any, result: any) {
69
      if (err) {
70
        reject(err);
71
      } else {
72
        resolve(result);
73
      }
74
    });
75
  });
76
}
77