0

Create Invoice

by
Published Jun 6, 2022

Creates an invoice. [See docs here](https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/invoice#create-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
    CustomerRef: {
13
      value: string;
14
      name?: string;
15
    };
16
    Line: {
17
      DetailType: "SalesItemLineDetail" | "GroupLineDetail" | "DescriptionOnly";
18
      Amount: number;
19
      Description?: string;
20
      LineNum?: number;
21
      SalesItemLineDetail?: {
22
        TaxInclusiveAmt?: number;
23
        DiscountAmt?: number;
24
        ItemRef?: {
25
          value: string;
26
          name?: string;
27
        };
28
        ClassRef?: {
29
          value: string;
30
          name?: string;
31
        };
32
        TaxCodeRef?: {
33
          value: string;
34
          name?: string;
35
        };
36
        MarkupInfo?: {
37
          PriceLevelRef?: {
38
            value: string;
39
            name?: string;
40
          };
41
          Percent?: number;
42
          MarkUpIncomeAccountRef?: {
43
            value: string;
44
            name?: string;
45
          };
46
        };
47
        ItemAccountRef?: {
48
          value: string;
49
          name?: string;
50
        };
51
        ServiceDate?: string;
52
        DiscountRate?: number;
53
        Qty?: number;
54
        UnitPrice?: number;
55
        TaxClassificationRef?: {
56
          value: string;
57
          name?: string;
58
        };
59
      };
60
      GroupLineDetail?: {
61
        Quantity?: number;
62
        Line?: {
63
          Id: string;
64
          DetailType: "SalesItemLineDetail";
65
          SalesItemLineDetail: {
66
            TaxInclusiveAmt?: number;
67
            DiscountAmt?: number;
68
            ItemRef?: {
69
              value: string;
70
              name?: string;
71
            };
72
            ClassRef?: {
73
              value: string;
74
              name?: string;
75
            };
76
            TaxCodeRef?: {
77
              value: string;
78
              name?: string;
79
            };
80
            MarkupInfo?: {
81
              PriceLevelRef?: {
82
                value: string;
83
                name?: string;
84
              };
85
              Percent?: number;
86
              MarkUpIncomeAccountRef?: {
87
                value: string;
88
                name?: string;
89
              };
90
            };
91
            ItemAccountRef?: {
92
              value: string;
93
              name?: string;
94
            };
95
            ServiceDate?: string;
96
            DiscountRate?: number;
97
            Qty?: number;
98
            UnitPrice?: number;
99
            TaxClassificationRef?: {
100
              value: string;
101
              name?: string;
102
            };
103
          };
104
          Amount: number;
105
          Description?: string;
106
          LineNum?: number;
107
        }[];
108
        GroupItemRef?: {
109
          value: string;
110
          name?: string;
111
        };
112
      };
113
      DescriptionLineDetail?: {
114
        TaxCodeRef?: {
115
          value: string;
116
          name?: string;
117
        };
118
        ServiceDate?: {
119
          date: string;
120
        };
121
      };
122
    }[];
123
    CurrencyRef?: {
124
      value: string;
125
      name?: string;
126
    };
127
    ProjectRef?: {
128
      value: string;
129
      name?: string;
130
    };
131
  }
132
) {
133
  const qbo = new QuickBooks("", "", resource.token, false, resource.realmId, resource.isSandBox, true, null, "2.0");
134

135
  return new Promise((resolve, reject) => {
136
    qbo.createInvoice(invoice, function (err: any, result: any) {
137
      if (err) {
138
        reject(err);
139
      } else {
140
        resolve(result);
141
      }
142
    });
143
  });
144
}
145