Edits history of script submission #19916 for ' Update an invoice (sage_intacct)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type SageIntacct = {
    	token: string
    }
    /**
     * Update an invoice
     * Updates an existing invoice by setting field values. Any fields not provided remain unchanged. Allowed edits depend on the state an invoice is in. For more information, see [About editing invoices](https://www.intacct.com/ia/docs/en_US/help_action/Accounts_Receivable/Invoices/Tasks/edit-an-invoice-overview.htm).
    
    
    Permissions and other requirements
    
    SubscriptionAccounts Receivable
    User typeBusiness, Employee, Approver
    PermissionsEdit Invoices
    
    
    
    
     */
    export async function main(
    	auth: SageIntacct,
    	key: string,
    	body: {
    		key?: string
    		id?: string
    		action?: 'submit' | 'draft'
    		recordType?: string
    		moduleKey?: 'accountsReceivable' | 'orderEntry'
    		invoiceNumber?: string
    		state?:
    			| 'draft'
    			| 'reversed'
    			| 'reversal'
    			| 'noValue'
    			| 'posted'
    			| 'paid'
    			| 'partiallyPaid'
    			| 'selected'
    		dueInDays?: number
    		referenceNumber?: string
    		description?: string
    		documentId?: string
    		discountCutOffDate?: string
    		invoiceDate?: string
    		dueDate?: string
    		currency?: {
    			baseCurrency?: string
    			txnCurrency?: string
    			exchangeRate?: { date?: string; rate?: number; typeId?: string }
    		}
    		totalBaseAmount?: string
    		totalBaseAmountDue?: string
    		totalTxnAmount?: string
    		totalTxnAmountDue?: string
    		dunningCount?: number
    		customerMessage?: {
    			key?: string
    			id?: string
    			message?: string
    			href?: string
    		}
    		recurringSchedule?: { key?: string }
    		paymentInformation?: {
    			fullyPaidDate?: string
    			totalBaseAmountPaid?: string
    			totalBaseAmountSelectedForPayment?: string
    			totalTxnAmountSelectedForPayment?: string
    			totalTxnAmountPaid?: string
    		}
    		contacts?: {
    			payTo?: { key?: string; id?: string }
    			returnTo?: {
    				key?: string
    				id?: string
    				tax?: {
    					taxId?: string
    					group?: { key?: string; id?: string; href?: string }
    				}
    			}
    		}
    		isSystemGeneratedDocument?: false | true
    		billbackTemplate?: { key?: string; id?: string; href?: string }
    		attachment?: { key?: string; id?: string; href?: string }
    		customer?: {
    			key?: string
    			id?: string
    			name?: string
    			emailOption?: false | true
    			customerDue?: string
    			deliveryOptions?: 'print' | 'email' | 'both'
    			href?: string
    		}
    		term?: { key?: string; id?: string; href?: string }
    		taxSolution?: { key?: string; id?: string; href?: string }
    		invoiceSummary?: {
    			key?: string
    			id?: string
    			glPostingDate?: string
    			isSummaryOpen?: 'open' | 'closed'
    			isSummaryPosted?: string
    			href?: string
    		}
    		lines?: {
    			key?: string
    			id?: string
    			glAccount?: { key?: string; id?: string; name?: string; href?: string }
    			overrideOffsetGLAccount?: {
    				key?: string
    				id?: string
    				name?: string
    				href?: string
    			}
    			baseAmount?: string
    			txnAmount?: string
    			memo?: string
    			currency?: {
    				baseCurrency?: string
    				txnCurrency?: string
    				exchangeRate?: { date?: string; rate?: number; typeId?: string }
    			}
    			paymentInformation?: {
    				totalBaseAmountPaid?: string
    				totalTxnAmountPaid?: string
    				totalBaseAmountSelectedForPayment?: string
    				totalTxnAmountSelectedForPayment?: string
    			}
    			allocation?: { key?: string; id?: string; href?: string }
    			lineNumber?: number
    			isSubtotal?: 'subtotal' | 'tax'
    			baseLocation?: {
    				key?: string
    				id?: string
    				name?: string
    				href?: string
    			} & { key?: string }
    			createdDate?: string
    			accountLabel?: {
    				key?: string
    				id?: string
    				name?: string
    				href?: string
    			}
    			taxEntries?: {
    				key?: string
    				id?: string
    				baseTaxAmount?: string
    				txnTaxAmount?: string
    				taxRate?: number
    			} & {
    				orderEntryTaxDetail?: { key?: string; id?: string; href?: string }
    				invoiceLine?: { id?: string; key?: string; href?: string }
    			}[]
    			dimensions?: {
    				location?: { key?: string; id?: string; name?: string; href?: string }
    				department?: {
    					key?: string
    					id?: string
    					name?: string
    					href?: string
    				}
    				employee?: { key?: string; id?: string; name?: string; href?: string }
    				project?: { key?: string; id?: string; name?: string; href?: string }
    				customer?: { key?: string; id?: string; name?: string; href?: string }
    				vendor?: { key?: string; id?: string; name?: string; href?: string }
    				item?: { key?: string; id?: string; name?: string; href?: string }
    				warehouse?: { 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 }
    				costType?: { id?: string; key?: string; name?: string; href?: string }
    				asset?: { id?: string; key?: string; name?: string; href?: string }
    				contract?: { id?: string; key?: string; name?: string; href?: string }
    				affiliateEntity?: {
    					key?: string
    					id?: string
    					href?: string
    					name?: string
    				}
    			} & {
    				location?: { key?: string; id?: string; name?: string; href?: string }
    				department?: {
    					key?: string
    					id?: string
    					name?: string
    					href?: string
    				}
    			}
    			invoice?: { id?: string; key?: string; href?: string }
    			audit?: {
    				createdDateTime?: string
    				modifiedDateTime?: string
    				createdBy?: string
    				modifiedBy?: string
    			}
    		}[]
    		entity?: { key?: string; id?: string; name?: string; href?: string }
    		audit?: {
    			createdDateTime?: string
    			modifiedDateTime?: string
    			createdBy?: string
    			modifiedBy?: string
    		} & { createdDateTime?: string }
    	} & { id?: {} }
    ) {
    	const url = new URL(
    		`https://api.intacct.com/ia/api/v1/objects/accounts-receivable/invoice/${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