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

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type SageIntacct = {
    	token: string
    }
    /**
     * Update a contract line
     * Updates an existing contract line 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
    		state?:
    			| 'draft'
    			| 'inProgress'
    			| 'renewalOnly'
    			| 'canceled'
    			| 'notRenewed'
    			| 'completed'
    			| 'revalued'
    			| 'closed'
    			| 'renewalForecast'
    		lineNumber?: number
    		recurringBillingPeriod?: number
    		startDate?: string
    		endDate?: string
    		cancelationDate?: string
    		changeType?:
    			| 'newMRR'
    			| 'addOnMRR'
    			| 'renewalUpgrade'
    			| 'renewalDowngrade'
    			| 'churnMRR'
    			| 'downgrade'
    		itemDescription?: string
    		priceCalculationMemo?: string
    		deliveryStatus?: 'delivered' | 'undelivered'
    		deliveryDate?: string
    		postingDate?: string
    		lineType?: 'sale' | 'discount' | 'debook'
    		memo?: string
    		shipToSource?: 'contractValue' | 'userSpecifiedValue'
    		billToSource?: 'contractValue' | 'userSpecifiedValue'
    		revenueDeferralStatus?:
    			| 'deferRevenueUntilItemIsDelivered'
    			| 'deferRevenueUntilAllItemsAreDelivered'
    		isRecurring?: false | true
    		currency?: {
    			exchangeRateDate?: string
    			exchangeRate?: string
    			baseCurrency?: string
    			txnCurrency?: string
    		}
    		billing?: {
    			amountFrequency?: 'oneTime' | 'useBillingTemplate' | 'includeWithEveryInvoice'
    			template?: { key?: string; id?: string; method?: string; href?: string }
    			schedule?: {
    				key?: string
    				id?: string
    				status?:
    					| 'draft'
    					| 'inProgress'
    					| 'completed'
    					| 'renewalForecast'
    					| 'onHold'
    					| 'terminated'
    					| 'estimateRevalued'
    				href?: string
    			}
    			method?: 'fixedPrice' | 'quantityBased' | 'projectT&M' | 'projectTime' | 'projectMaterials'
    			usageQuantityReset?: 'afterEachRenewal' | 'afterEachInvoice'
    			isUsageQuantityRecurring?: false | true
    			committedQuantityEndAction?: 'billUnusedQuantity' | 'cancelUnusedQuantity' | 'doNothing'
    			committedQuantityExcess?: 'doNothing' | 'billOverage' | 'doNotAllowOverage'
    			quantityType?: 'variable' | 'committed'
    			durationInPeriods?: string
    			proratePartialPeriods?: false | true
    			frequency?: 'monthly' | 'quarterly' | 'annually'
    			startDate?: string
    			endDate?: string
    			holdDate?: string
    			resumeDate?: string
    			memo?: string
    			quantity?: string
    			rate?: string
    			multiplier?: string
    			discount?: string
    			flatFixedAmount?: string
    			baseFlatFixedAmount?: string
    			totalFlatFixedAmount?: string
    			totalBaseFlatFixedAmount?: string
    		}
    		expense?: { holdDate?: string; resumeDate?: string; memo?: string }
    		revenue?: {
    			journal1?: {
    				glJournal?: { key?: string; id?: string; name?: string; href?: string }
    				revenueTemplate?: {
    					key?: string
    					id?: string
    					recognitionMethod?: string
    					href?: string
    				}
    				revenueSchedule?: {
    					key?: string
    					id?: string
    					status?:
    						| 'draft'
    						| 'inProgress'
    						| 'completed'
    						| 'renewalForecast'
    						| 'onHold'
    						| 'terminated'
    						| 'estimateRevalued'
    						| 'pendingDelivery'
    						| 'pendingDeliveryAll'
    					href?: string
    				}
    				startDate?: string
    				endDate?: string
    			}
    			journal2?: {
    				glJournal?: { key?: string; id?: string; name?: string; href?: string }
    				revenueTemplate?: {
    					key?: string
    					id?: string
    					recognitionMethod?: string
    					href?: string
    				}
    				revenueSchedule?: {
    					key?: string
    					id?: string
    					status?:
    						| 'draft'
    						| 'inProgress'
    						| 'completed'
    						| 'renewalForecast'
    						| 'onHold'
    						| 'terminated'
    						| 'estimateRevalued'
    						| 'pendingDelivery'
    						| 'pendingDeliveryAll'
    					href?: string
    				}
    				startDate?: string
    				endDate?: string
    			}
    			totalQuantity?: string
    			resumeDate?: string
    			holdDate?: string
    			memo?: string
    		}
    		renewal?: {
    			renew?: false | true
    			billingTemplate?: { key?: string; id?: string; href?: string }
    		}
    		contacts?: {
    			shipTo?: { key?: string; id?: string; href?: string }
    			billTo?: { key?: string; id?: string; href?: string }
    		}
    		contract?: {
    			key?: string
    			id?: string
    			endDate?: string
    			termType?: string
    			state?: 'draft' | 'inProgress' | 'canceled' | 'notRenewed' | 'renewed'
    			name?: string
    			href?: string
    		}
    		item?: { key?: string; id?: string; name?: string; href?: string }
    		renewalTriggerDate?: string
    		lineRenewalDate?: string
    		parent?: { key?: string; id?: string; lineNumber?: string; href?: 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 }
    		}
    	}
    ) {
    	const url = new URL(`https://api.intacct.com/ia/api/v1/objects/contracts/contract-line/${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