Edits history of script submission #18949 for ' Create an invoice (sage_intacct)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type SageIntacct = {
    	token: string
    }
    /**
     * Create an invoice
     * Creates a new invoice. For the invoice to be posted, you must specify at least the account and an amount for each line item.
    
    
    Permissions and other requirements
    
    SubscriptionAccounts Receivable
    User typeBusiness, Employee, Approver
    PermissionsAdd Invoices
    
    
    
    
     */
    export async function main(
    	auth: SageIntacct,
    	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 }
    	} & {
    		customer?: {}
    		lines?: { glAccount?: {}; dimensions?: { location?: {} } }[]
    	}
    ) {
    	const url = new URL(`https://api.intacct.com/ia/api/v1/objects/accounts-receivable/invoice`)
    
    	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