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