1 | |
2 | type SageIntacct = { |
3 | token: string |
4 | } |
5 | |
6 | * Update a contract |
7 | * Updates an existing contract 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 | name?: string |
17 | parent?: { key?: string; id?: string; href?: string } |
18 | description?: string |
19 | status?: 'active' | 'inactive' |
20 | state?: 'draft' | 'inProgress' | 'renewed' | 'canceled' | 'notRenewed' |
21 | application?: 'contracts' | 'orderEntry' |
22 | startDate?: string |
23 | endDate?: string |
24 | contacts?: { |
25 | shipTo?: { |
26 | key?: string |
27 | id?: string |
28 | email1?: string |
29 | email2?: string |
30 | href?: string |
31 | } |
32 | billTo?: { |
33 | key?: string |
34 | id?: string |
35 | email1?: string |
36 | email2?: string |
37 | href?: string |
38 | } |
39 | additionalContact?: { |
40 | key?: string |
41 | id?: string |
42 | email1?: string |
43 | email2?: string |
44 | href?: string |
45 | } |
46 | } |
47 | cancellationDate?: string |
48 | billingFrequency?: 'monthly' | 'quarterly' | 'annually' |
49 | paymentTerm?: { key?: string; id?: string; href?: string } |
50 | billingPriceList?: { key?: string; id?: string; href?: string } |
51 | meaPriceList?: { key?: string; id?: string; href?: string } |
52 | holdBilling?: false | true |
53 | holdRevenue?: false | true |
54 | holdExpense?: false | true |
55 | currency?: { |
56 | exchangeRateType?: string |
57 | baseCurrency?: string |
58 | txnCurrency?: string |
59 | } |
60 | isRenewable?: false | true |
61 | renewedContract?: { key?: string; id?: string; href?: string } |
62 | renewal?: { |
63 | template?: string |
64 | contractTermType?: 'termed' | 'evergreen' |
65 | termLength?: number |
66 | termPeriod?: 'years' | 'months' | 'days' |
67 | triggerDate?: string |
68 | date?: string |
69 | billInAdvanceLength?: number |
70 | billInAdvancePeriod?: 'months' | 'days' |
71 | } |
72 | billInAdvanceLength?: number |
73 | billInAdvancePeriod?: 'months' | 'days' |
74 | contractType?: { key?: string; name?: string; href?: string } |
75 | deferEstimatedTimeBasedRevenueBy?: 'project' | 'projectAndItem' | 'projectAndTask' |
76 | contractTotalAmount?: string |
77 | billedAmount?: string |
78 | attachment?: { key?: string; id?: string; href?: string } |
79 | postMemo?: string |
80 | dimensions?: { |
81 | location?: { key?: string; id?: string; name?: string; href?: string } |
82 | department?: { key?: string; id?: string; name?: string; href?: string } |
83 | class?: { key?: string; id?: string; name?: string; href?: string } |
84 | task?: { id?: string; key?: string; name?: string; href?: string } |
85 | vendor?: { key?: string; id?: string; name?: string; href?: string } |
86 | customer?: { key?: string; id?: string; name?: string; href?: string } |
87 | project?: { key?: string; id?: string; name?: string; href?: string } |
88 | employee?: { key?: string; id?: string; name?: string; href?: string } |
89 | } |
90 | audit?: { |
91 | createdDateTime?: string |
92 | modifiedDateTime?: string |
93 | createdBy?: string |
94 | modifiedBy?: string |
95 | createdByUser?: { key?: string; id?: string; href?: string } |
96 | modifiedByUser?: { key?: string; id?: string; href?: string } |
97 | } |
98 | } & { id?: {} } |
99 | ) { |
100 | const url = new URL(`https://api.intacct.com/ia/api/v1/objects/contracts/contract/${key}`) |
101 |
|
102 | const response = await fetch(url, { |
103 | method: 'PATCH', |
104 | headers: { |
105 | 'Content-Type': 'application/json', |
106 | Authorization: 'Bearer ' + auth.token |
107 | }, |
108 | body: JSON.stringify(body) |
109 | }) |
110 | if (!response.ok) { |
111 | const text = await response.text() |
112 | throw new Error(`${response.status} ${text}`) |
113 | } |
114 | return await response.json() |
115 | } |
116 |
|