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