Edits history of script submission #18931 for ' Create an employee expense (sage_intacct)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type SageIntacct = {
    	token: string
    }
    /**
     * Create an employee expense
     * Creates a new employee expense. You must specify a unique employee expense ID when creating an employee expense unless document sequencing is configured, in which case the ID is auto-generated.
    
    
    Permissions and other requirements
    
    SubscriptionTime & Expenses
    User typeBusiness, Employee
    PermissionsAdd Expenses
    
    
    
    
     */
    export async function main(
    	auth: SageIntacct,
    	body: {
    		key?: string
    		id?: string
    		createdDate?: string
    		employee?: { key?: string; id?: string; href?: string }
    		employeeContact?: {
    			key?: string
    			id?: string
    			firstName?: string
    			lastName?: string
    			href?: string
    		}
    		state?:
    			| 'draft'
    			| 'submitted'
    			| 'partiallyApproved'
    			| 'partiallyDeclined'
    			| 'approved'
    			| 'posted'
    			| 'declined'
    			| 'reversalPending'
    			| 'reversed'
    			| 'reversal'
    			| 'paid'
    			| 'confirmed'
    			| 'voided'
    			| 'partiallyPaid'
    			| 'selected'
    		basePayment?: {
    			baseCurrency?: string
    			paidDate?: string
    			totalEntered?: string
    			totalPaid?: string
    			totalDue?: string
    			totalSelected?: string
    		}
    		reimbursement?: {
    			reimbursementCurrency?: string
    			totalEntered?: string
    			totalPaid?: string
    			totalDue?: string
    			totalSelected?: string
    		}
    		expenseReportNumber?: string
    		expenseSummary?: {
    			key?: string
    			id?: string
    			title?: string
    			postingDate?: string
    			state?: 'open' | 'closed'
    			preventGLPosting?: false | true
    			href?: string
    		}
    		nonReimbursable?: {
    			baseTotalEntered?: string
    			reimbursementTotalEntered?: string
    		}
    		memo?: string
    		description?: string
    		reclassificationNotes?: string
    		attachment?: { key?: string; id?: string; href?: string }
    		audit?: {
    			createdDateTime?: string
    			modifiedDateTime?: string
    			createdBy?: string
    			modifiedBy?: string
    		} & { createdDateTime?: string }
    		lines?: {
    			key?: string
    			id?: string
    			href?: string
    			entryDate?: string
    			baseCurrency?: string
    			baseAmount?: string
    			reimbursementCurrency?: string
    			reimbursementAmount?: string
    			txnCurrency?: string
    			txnAmount?: string
    			totalSelected?: string
    			totalPaid?: string
    			quantity?: string
    			unitRate?: string
    			paidTo?: string
    			paidFor?: string
    			glAccount?: { key?: string; id?: string; name?: string; href?: string }
    			expenseType?: { key?: string; id?: string; href?: string }
    			lineNumber?: number
    			reimburseToBaseConversion?: {
    				exchangeRateDate?: string
    				exchangeRateTypeId?: string
    				exchangeRate?: string
    			}
    			transactionToReimburseConversion?: {
    				exchangeRate?: string
    				exchangeRateDate?: string
    				exchangeRateTypeId?: string
    			}
    			state?:
    				| 'draft'
    				| 'submitted'
    				| 'partiallyApproved'
    				| 'partiallyDeclined'
    				| 'approved'
    				| 'posted'
    				| 'declined'
    				| 'reversalPending'
    				| 'reversed'
    				| 'reversal'
    				| 'paid'
    				| 'confirmed'
    				| 'voided'
    				| 'partiallyPaid'
    				| 'saved'
    			isBillable?: false | true
    			isBilled?: false | true
    			form1099?: { isForm1099?: string; type?: string; box?: string }
    			paymentType?: {
    				key?: string
    				id?: string
    				isNonReimbursable?: false | true
    				href?: string
    			}
    			electronicReceipt?: { id?: string; key?: string; href?: string }
    			electronicReceiptLine?: { id?: string; key?: string; href?: string }
    			audit?: {
    				createdDateTime?: string
    				modifiedDateTime?: string
    				createdBy?: string
    				modifiedBy?: 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
    				}
    			}
    			employeeExpense?: { id?: string; key?: string; href?: string }
    		}[]
    		entity?: { key?: string; id?: string; name?: string; href?: string }
    	} & {}
    ) {
    	const url = new URL(`https://api.intacct.com/ia/api/v1/objects/expenses/employee-expense`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		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