Edits history of script submission #19769 for ' Update a contract (sage_intacct)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type SageIntacct = {
    	token: string
    }
    /**
     * Update a contract
     * Updates an existing contract by setting field values. Any fields not provided remain unchanged.
     */
    export async function main(
    	auth: SageIntacct,
    	key: string,
    	body: {
    		key?: string
    		id?: string
    		href?: string
    		name?: string
    		parent?: { key?: string; id?: string; href?: string }
    		description?: string
    		status?: 'active' | 'inactive'
    		state?: 'draft' | 'inProgress' | 'renewed' | 'canceled' | 'notRenewed'
    		application?: 'contracts' | 'orderEntry'
    		startDate?: string
    		endDate?: string
    		contacts?: {
    			shipTo?: {
    				key?: string
    				id?: string
    				email1?: string
    				email2?: string
    				href?: string
    			}
    			billTo?: {
    				key?: string
    				id?: string
    				email1?: string
    				email2?: string
    				href?: string
    			}
    			additionalContact?: {
    				key?: string
    				id?: string
    				email1?: string
    				email2?: string
    				href?: string
    			}
    		}
    		cancellationDate?: string
    		billingFrequency?: 'monthly' | 'quarterly' | 'annually'
    		paymentTerm?: { key?: string; id?: string; href?: string }
    		billingPriceList?: { key?: string; id?: string; href?: string }
    		meaPriceList?: { key?: string; id?: string; href?: string }
    		holdBilling?: false | true
    		holdRevenue?: false | true
    		holdExpense?: false | true
    		currency?: {
    			exchangeRateType?: string
    			baseCurrency?: string
    			txnCurrency?: string
    		}
    		isRenewable?: false | true
    		renewedContract?: { key?: string; id?: string; href?: string }
    		renewal?: {
    			template?: string
    			contractTermType?: 'termed' | 'evergreen'
    			termLength?: number
    			termPeriod?: 'years' | 'months' | 'days'
    			triggerDate?: string
    			date?: string
    			billInAdvanceLength?: number
    			billInAdvancePeriod?: 'months' | 'days'
    		}
    		billInAdvanceLength?: number
    		billInAdvancePeriod?: 'months' | 'days'
    		contractType?: { key?: string; name?: string; href?: string }
    		deferEstimatedTimeBasedRevenueBy?: 'project' | 'projectAndItem' | 'projectAndTask'
    		contractTotalAmount?: string
    		billedAmount?: string
    		attachment?: { key?: string; id?: string; href?: string }
    		postMemo?: string
    		dimensions?: {
    			location?: { key?: string; id?: string; name?: string; href?: string }
    			department?: { key?: string; id?: string; name?: string; href?: string }
    			class?: { key?: string; id?: string; name?: string; href?: string }
    			task?: { id?: string; key?: string; name?: string; href?: string }
    			vendor?: { key?: string; id?: string; name?: string; href?: string }
    			customer?: { key?: string; id?: string; name?: string; href?: string }
    			project?: { key?: string; id?: string; name?: string; href?: string }
    			employee?: { key?: string; id?: string; name?: string; href?: string }
    		}
    		audit?: {
    			createdDateTime?: string
    			modifiedDateTime?: string
    			createdBy?: string
    			modifiedBy?: string
    			createdByUser?: { key?: string; id?: string; href?: string }
    			modifiedByUser?: { key?: string; id?: string; href?: string }
    		}
    	} & { id?: {} }
    ) {
    	const url = new URL(`https://api.intacct.com/ia/api/v1/objects/contracts/contract/${key}`)
    
    	const response = await fetch(url, {
    		method: 'PATCH',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.token
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago