1 | |
2 | type SageIntacct = { |
3 | token: string |
4 | } |
5 | |
6 | * Create contract usage |
7 | * Creates a new contract usage |
8 | */ |
9 | export async function main( |
10 | auth: SageIntacct, |
11 | body: { |
12 | key?: string |
13 | id?: string |
14 | href?: string |
15 | contract?: { key?: string; id?: string; name?: string; href?: string } |
16 | contractLine?: { |
17 | key?: string |
18 | id?: string |
19 | lineNumber?: string |
20 | href?: string |
21 | } |
22 | usageDate?: string |
23 | quantity?: string |
24 | item?: { key?: string; id?: string; name?: string; href?: string } |
25 | usageType?: |
26 | | 'billingVariable' |
27 | | 'revenue' |
28 | | 'canceled' |
29 | | 'trackedRevenue' |
30 | | 'billingCommitted' |
31 | | 'trackedVariable' |
32 | | 'billingOverage' |
33 | documentId?: string |
34 | revenueSchedule?: { key?: string; id?: string; href?: string } |
35 | revenueScheduleLine?: { |
36 | key?: string |
37 | id?: string |
38 | postingDate?: string |
39 | amount?: string |
40 | href?: string |
41 | } |
42 | revenue2Schedule?: { key?: string; id?: string; href?: string } |
43 | revenue2ScheduleLine?: { |
44 | key?: string |
45 | id?: string |
46 | postingDate?: string |
47 | amount?: string |
48 | href?: string |
49 | } |
50 | contractUsageBilling?: { billedDate?: string; recurringUsageDate?: string } |
51 | customer?: { key?: string; id?: string; name?: string; href?: string } |
52 | servicePeriodStartDate?: string |
53 | servicePeriodEndDate?: string |
54 | audit?: { |
55 | createdDateTime?: string |
56 | modifiedDateTime?: string |
57 | createdBy?: string |
58 | modifiedBy?: string |
59 | createdByUser?: { key?: string; id?: string; href?: string } |
60 | modifiedByUser?: { key?: string; id?: string; href?: string } |
61 | } |
62 | } & {} |
63 | ) { |
64 | const url = new URL(`https://api.intacct.com/ia/api/v1/objects/contracts/contract-usage`) |
65 |
|
66 | const response = await fetch(url, { |
67 | method: 'POST', |
68 | headers: { |
69 | 'Content-Type': 'application/json', |
70 | Authorization: 'Bearer ' + auth.token |
71 | }, |
72 | body: JSON.stringify(body) |
73 | }) |
74 | if (!response.ok) { |
75 | const text = await response.text() |
76 | throw new Error(`${response.status} ${text}`) |
77 | } |
78 | return await response.json() |
79 | } |
80 |
|