1 | |
2 | type Holded = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Create Document |
7 | * Create a new document type. |
8 | */ |
9 | export async function main( |
10 | auth: Holded, |
11 | docType: string, |
12 | body: { |
13 | applyContactDefaults?: false | true; |
14 | contactCode?: string; |
15 | contactId?: string; |
16 | contactName?: string; |
17 | contactEmail?: string; |
18 | contactAddress?: string; |
19 | contactCity?: string; |
20 | contactCp?: string; |
21 | contactProvince?: string; |
22 | contactCountryCode?: string; |
23 | desc?: string; |
24 | date: number; |
25 | notes?: string; |
26 | salesChannelId?: string; |
27 | paymentMethodId?: string; |
28 | designId?: string; |
29 | language?: string; |
30 | warehouseId?: string; |
31 | approveDoc?: false | true; |
32 | items?: { |
33 | name?: string; |
34 | desc?: string; |
35 | units?: number; |
36 | sku?: string; |
37 | serviceId?: string; |
38 | accountingAccountId?: string; |
39 | subtotal?: number; |
40 | discount?: number; |
41 | tax?: number; |
42 | taxes?: string[]; |
43 | supplied?: string; |
44 | tags?: string[]; |
45 | }[]; |
46 | customFields?: { field?: string; value?: string }[]; |
47 | invoiceNum?: string; |
48 | numSerieId?: string; |
49 | currency?: string; |
50 | currencyChange?: number; |
51 | tags?: string[]; |
52 | dueDate?: number; |
53 | shippingAddress?: string; |
54 | shippingPostalCode?: string; |
55 | shippingCity?: string; |
56 | shippingProvince?: string; |
57 | shippingCountry?: string; |
58 | salesChannel?: number; |
59 | }, |
60 | ) { |
61 | const url = new URL( |
62 | `https://api.holded.com/api/invoicing/v1/documents/${docType}`, |
63 | ); |
64 |
|
65 | const response = await fetch(url, { |
66 | method: "POST", |
67 | headers: { |
68 | "Content-Type": "application/json", |
69 | key: auth.apiKey, |
70 | }, |
71 | body: JSON.stringify(body), |
72 | }); |
73 | if (!response.ok) { |
74 | const text = await response.text(); |
75 | throw new Error(`${response.status} ${text}`); |
76 | } |
77 | return await response.json(); |
78 | } |
79 |
|