Edits history of script submission #18897 for ' Create a vendor (sage_intacct)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type SageIntacct = {
    	token: string
    }
    /**
     * Create a vendor
     * Creates a new vendor. When you add a new vendor, you can provide key descriptive information about that vendor and establish how you want to pay them.
    
    
    Permissions and other requirements
    
    SubscriptionAccounts Payable
    User typeBusiness
    PermissionsList, View, Add, Edit Vendors (Bank Details permissions required to access vendor bank account.)
    
    
    
    
     */
    export async function main(
    	auth: SageIntacct,
    	body: {
    		key?: string
    		id?: string
    		name?: string
    		isOneTimeUse?: false | true
    		href?: string
    		status?: 'active' | 'activeNonPosting' | 'inactive'
    		state?: 's' | 'a' | 'r'
    		vendorType?: { key?: string; id?: string; href?: string }
    		parent?: { key?: string; id?: string; name?: string; href?: string }
    		accountGroup?: { key?: string; id?: string; href?: string }
    		accountlabel?: { key?: string; id?: string; href?: string }
    		defaultLeadTime?: number
    		filePaymentService?: 'ach' | 'bankFile' | 'none'
    		bankFiles?: {
    			paymentCountryCode?:
    				| 'us'
    				| 'af'
    				| 'ax'
    				| 'al'
    				| 'dz'
    				| 'as'
    				| 'ad'
    				| 'ao'
    				| 'ai'
    				| 'aq'
    				| 'ag'
    				| 'ar'
    				| 'am'
    				| 'aw'
    				| 'au'
    				| 'at'
    				| 'az'
    				| 'bs'
    				| 'bh'
    				| 'bd'
    				| 'bb'
    				| 'by'
    				| 'be'
    				| 'bz'
    				| 'bj'
    				| 'bm'
    				| 'bt'
    				| 'bo'
    				| 'bq'
    				| 'ba'
    				| 'bw'
    				| 'bv'
    				| 'br'
    				| 'io'
    				| 'bn'
    				| 'bg'
    				| 'bf'
    				| 'bi'
    				| 'kh'
    				| 'cm'
    				| 'ca'
    				| 'cv'
    				| 'ky'
    				| 'cf'
    				| 'td'
    				| 'cl'
    				| 'cn'
    				| 'cx'
    				| 'cc'
    				| 'co'
    				| 'km'
    				| 'cg'
    				| 'cd'
    				| 'ck'
    				| 'cr'
    				| 'ci'
    				| 'hr'
    				| 'cu'
    				| 'cw'
    				| 'cy'
    				| 'cz'
    				| 'dk'
    				| 'dj'
    				| 'dm'
    				| 'do'
    				| 'ec'
    				| 'eg'
    				| 'sv'
    				| 'gq'
    				| 'er'
    				| 'ee'
    				| 'sz'
    				| 'et'
    				| 'fk'
    				| 'fo'
    				| 'fj'
    				| 'fi'
    				| 'fr'
    				| 'gf'
    				| 'pf'
    				| 'tf'
    				| 'ga'
    				| 'gm'
    				| 'ge'
    				| 'de'
    				| 'gh'
    				| 'gi'
    				| 'gr'
    				| 'gl'
    				| 'gd'
    				| 'gp'
    				| 'gu'
    				| 'gt'
    				| 'gg'
    				| 'gn'
    				| 'gw'
    				| 'gy'
    				| 'ht'
    				| 'hm'
    				| 'hn'
    				| 'hk'
    				| 'hu'
    				| 'is'
    				| 'in'
    				| 'id'
    				| 'ir'
    				| 'iq'
    				| 'ie'
    				| 'im'
    				| 'il'
    				| 'it'
    				| 'jm'
    				| 'jp'
    				| 'je'
    				| 'jo'
    				| 'kz'
    				| 'ke'
    				| 'ki'
    				| 'kr'
    				| 'kp'
    				| 'xk'
    				| 'kw'
    				| 'kg'
    				| 'la'
    				| 'lv'
    				| 'lb'
    				| 'ls'
    				| 'lr'
    				| 'ly'
    				| 'li'
    				| 'lt'
    				| 'lu'
    				| 'mo'
    				| 'mk'
    				| 'mg'
    				| 'mw'
    				| 'my'
    				| 'mv'
    				| 'ml'
    				| 'mt'
    				| 'mh'
    				| 'mq'
    				| 'mr'
    				| 'mu'
    				| 'yt'
    				| 'mx'
    				| 'fm'
    				| 'md'
    				| 'mc'
    				| 'mn'
    				| 'me'
    				| 'ms'
    				| 'ma'
    				| 'mz'
    				| 'mm'
    				| 'na'
    				| 'nr'
    				| 'np'
    				| 'nl'
    				| 'an'
    				| 'nc'
    				| 'nz'
    				| 'ni'
    				| 'ne'
    				| 'ng'
    				| 'nu'
    				| 'nf'
    				| 'mp'
    				| 'no'
    				| 'om'
    				| 'pk'
    				| 'pw'
    				| 'ps'
    				| 'pa'
    				| 'pg'
    				| 'py'
    				| 'pe'
    				| 'ph'
    				| 'pn'
    				| 'pl'
    				| 'pt'
    				| 'pr'
    				| 'qa'
    				| 're'
    				| 'ro'
    				| 'ru'
    				| 'rw'
    				| 'bl'
    				| 'sh'
    				| 'kn'
    				| 'lc'
    				| 'mf'
    				| 'pm'
    				| 'vc'
    				| 'ws'
    				| 'sm'
    				| 'st'
    				| 'sa'
    				| 'sn'
    				| 'rs'
    				| 'sc'
    				| 'sl'
    				| 'sg'
    				| 'sx'
    				| 'sk'
    				| 'si'
    				| 'sb'
    				| 'so'
    				| 'za'
    				| 'gs'
    				| 'es'
    				| 'lk'
    				| 'sd'
    				| 'ss'
    				| 'sr'
    				| 'sj'
    				| 'se'
    				| 'ch'
    				| 'sy'
    				| 'tw'
    				| 'tj'
    				| 'tz'
    				| 'th'
    				| 'tl'
    				| 'tg'
    				| 'tk'
    				| 'to'
    				| 'tt'
    				| 'tn'
    				| 'tr'
    				| 'tm'
    				| 'tc'
    				| 'tv'
    				| 'ug'
    				| 'ua'
    				| 'ae'
    				| 'gb'
    				| 'um'
    				| 'uy'
    				| 'uz'
    				| 'vu'
    				| 'va'
    				| 've'
    				| 'vn'
    				| 'vg'
    				| 'vi'
    				| 'wf'
    				| 'eh'
    				| 'ye'
    				| 'zm'
    				| 'zw'
    			paymentCurrency?: string
    		}
    		taxId?: string
    		tpar?: { isTparEnabled?: false | true; name?: string }
    		t5018?: { isT5018Enabled?: false | true; t5018Number?: string }
    		form1099?: {
    			is1099Eligible?: false | true
    			nameOn1099?: string
    			type?: string
    			box?: string
    		}
    		attachment?: { key?: string; id?: string; href?: string }
    		isOnHold?: false | true
    		doNotPay?: false | true
    		alwaysCreateBill?: false | true
    		creditLimit?: number
    		retainagePercentage?: number
    		notes?: string
    		priceList?: { key?: string; id?: string; href?: string }
    		priceSchedule?: { key?: string; id?: string; href?: string }
    		overrideOffsetGLAccount?: {
    			key?: string
    			id?: string
    			name?: string
    			href?: string
    		}
    		defaultExpenseGLAccount?: {
    			key?: string
    			id?: string
    			name?: string
    			href?: string
    		}
    		discountPercent?: number
    		contacts?: {
    			default?: {
    				key?: string
    				id?: string
    				href?: string
    				lastName?: string
    				firstName?: string
    				middleName?: string
    				prefix?: string
    				printAs?: string
    				email1?: string
    				email2?: string
    				phone1?: string
    				phone2?: string
    				mobile?: string
    				pager?: string
    				fax?: string
    				URL1?: string
    				URL2?: string
    				companyName?: string
    				mailingAddress?: {
    					addressLine1?: string
    					addressLine2?: string
    					addressLine3?: string
    					city?: string
    					state?: string
    					postCode?: string
    					country?: string
    				}
    			} & {
    				hideContactList?: false | true
    				tax?: {
    					isTaxable?: false | true
    					group?: { key?: string; id?: string; href?: string }
    				}
    				electronicInvoiceDetails?: {
    					legalCategory?: string
    					mainActivity?: string
    					typeOfCompany?: string
    					registeredCapital?: number
    					valueAddedTaxRegime?: string
    				}
    				internationalTaxId?: string
    			}
    			primary?: { key?: string; id?: string; href?: string }
    			payTo?: { key?: string; id?: string; href?: string }
    			returnTo?: { key?: string; id?: string; href?: string }
    			recipient1099?: { key?: string; id?: string; href?: string }
    		}
    		contactList?: {
    			key?: string
    			id?: string
    			href?: string
    			categoryName?: string
    			contact?: { key?: string; id?: string; href?: string }
    			audit?: {
    				createdDateTime?: string
    				modifiedDateTime?: string
    				createdBy?: string
    				modifiedBy?: string
    			}
    			vendor?: { key?: string; id?: string; href?: string }
    		}[]
    		vendorEmailTemplates?: {
    			key?: string
    			id?: string
    			href?: string
    			vendor?: { key?: string; id?: string; href?: string }
    			txnDefinitionName?: string
    			emailTemplate?: {
    				key?: string
    				id?: string
    				name?: string
    				href?: string
    			}
    		}[]
    		vendorPaymentProviders?: {
    			key?: string
    			id?: string
    			href?: string
    			paymentProvider?: {
    				key?: string
    				id?: string
    				name?: string
    				href?: string
    			}
    			vendor?: { key?: string; id?: string; name?: string; href?: string }
    			state?:
    				| 'requestInitiated'
    				| 'inProgress'
    				| 'requestReceived'
    				| 'requestFailed'
    				| 'awaitingAuthorization'
    				| 'subscribed'
    				| 'canceled'
    				| 'suspended'
    			preferredPaymentMethod?: {
    				key?: string
    				id?: string
    				name?: string
    				href?: string
    			}
    			status?: 'active' | 'inactive'
    			audit?: {
    				createdDateTime?: string
    				modifiedDateTime?: string
    				createdBy?: string
    				modifiedBy?: string
    			}
    		}[]
    		vendorBankFileSetup?: {
    			key?: string
    			id?: string
    			bankAccountNumber?: string
    			bankAccountName?: string
    			bsbNumber?: string
    			sortCode?: string
    			paymentReference?: string
    			branchCode?: string
    			bankAccountType?: string
    			bankAccountCode?: string
    			printPaymentProof?: false | true
    			businessIdCode?: string
    			creditorCode?: string
    			secondaryIdentifier?: string
    			vendor?: { key?: string; id?: string; href?: string }
    			href?: string
    		}[]
    		vendorAccountNumberList?: {
    			key?: string
    			id?: string
    			location?: { key?: string; id?: string; name?: string; href?: string }
    			vendorAccountNumber?: string
    			href?: string
    			vendor?: { key?: string; id?: string; href?: string }
    		}[]
    		preferredPaymentMethod?:
    			| 'printedCheck'
    			| 'chargeCard'
    			| 'EFT'
    			| 'cash'
    			| 'ACH'
    			| 'wellsFargoCheck'
    			| 'wellsFargoUSDWire'
    			| 'wellsFargoDomesticACH'
    		mergePaymentRequests?: false | true
    		sendPaymentNotification?: false | true
    		billingType?: 'openItem' | 'balanceForward'
    		paymentPriority?: 'urgent' | 'high' | 'normal' | 'low'
    		currency?: string
    		displayTermDiscountOnCheckStub?: false | true
    		term?: { key?: string; id?: string; href?: string }
    		billPayment?: {
    			defaultDateOptions?: 'none' | 'dueDate' | 'billDate' | 'discountDate'
    			offsetTypePlusMinus?: '+' | '-'
    			dueNumberOfDays?: number
    			billNumberOfDays?: number
    		}
    		vendorAccountNumber?: string
    		displayVendorAccountOnCheckStub?: false | true
    		totalDue?: string
    		lastBillCreatedDate?: string
    		lastPaymentMadeDate?: string
    		ach?: {
    			enablePayments?: false | true
    			routingNumber?: string
    			accountNumber?: string
    			accountType?: 'checkingAccount' | 'savingsAccount'
    			remittanceType?: 'businessCTX' | 'personalPPD' | 'businessCCD'
    		}
    		vendorRestriction?: 'unrestricted' | 'rootOnly' | 'restricted'
    		restrictedLocations?: {
    			key?: string
    			id?: string
    			href?: string
    			location?: { key?: string; id?: string; href?: string }
    			locationGroup?: { key?: string; id?: string; href?: string }
    			vendor?: { key?: string; id?: string; href?: string }
    		}[]
    		restrictedDepartments?: {
    			key?: string
    			id?: string
    			href?: string
    			department?: { key?: string; id?: string; href?: string }
    			departmentGroup?: { key?: string; id?: string; href?: string }
    			vendor?: { key?: string; id?: string; href?: string }
    		}[]
    		audit?: {
    			createdDateTime?: string
    			modifiedDateTime?: string
    			createdBy?: string
    			modifiedBy?: string
    		}
    		entity?: { key?: string; id?: string; name?: string; href?: string }
    	} & {}
    ) {
    	const url = new URL(`https://api.intacct.com/ia/api/v1/objects/accounts-payable/vendor`)
    
    	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