Edits history of script submission #10495 for ' Updates or creates one or more quotes (xero)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xero = {
    	token: string
    }
    /**
     * Updates or creates one or more quotes
     *
     */
    export async function main(
    	auth: Xero,
    	summarizeErrors: string | undefined,
    	xero_tenant_id: string,
    	Idempotency_Key: string,
    	body: {
    		Quotes?: {
    			QuoteID?: string
    			QuoteNumber?: string
    			Reference?: string
    			Terms?: string
    			Contact?: string
    			LineItems?: {
    				LineItemID?: string
    				Description?: string
    				Quantity?: number
    				UnitAmount?: number
    				ItemCode?: string
    				AccountCode?: string
    				AccountID?: string
    				TaxType?: string
    				TaxAmount?: number
    				Item?: { Code?: string; Name?: string; ItemID?: string }
    				LineAmount?: number
    				Tracking?: {
    					TrackingCategoryID?: string
    					TrackingOptionID?: string
    					Name?: string
    					Option?: string
    				}[]
    				DiscountRate?: number
    				DiscountAmount?: number
    				RepeatingInvoiceID?: string
    				Taxability?: 'TAXABLE' | 'NON_TAXABLE' | 'EXEMPT' | 'PART_TAXABLE' | 'NOT_APPLICABLE'
    				SalesTaxCodeId?: number
    				TaxBreakdown?: {
    					TaxComponentId?: string
    					Type?:
    						| 'SYSGST/USCOUNTRY'
    						| 'SYSGST/USSTATE'
    						| 'SYSGST/USCOUNTY'
    						| 'SYSGST/USCITY'
    						| 'SYSGST/USSPECIAL'
    					Name?: string
    					TaxPercentage?: number
    					TaxAmount?: number
    					TaxableAmount?: number
    					NonTaxableAmount?: number
    					ExemptAmount?: number
    					StateAssignedNo?: string
    					JurisdictionRegion?: string
    				}[]
    			}[]
    			Date?: string
    			DateString?: string
    			ExpiryDate?: string
    			ExpiryDateString?: string
    			Status?: 'DRAFT' | 'SENT' | 'DECLINED' | 'ACCEPTED' | 'INVOICED' | 'DELETED'
    			CurrencyCode?:
    				| 'AED'
    				| 'AFN'
    				| 'ALL'
    				| 'AMD'
    				| 'ANG'
    				| 'AOA'
    				| 'ARS'
    				| 'AUD'
    				| 'AWG'
    				| 'AZN'
    				| 'BAM'
    				| 'BBD'
    				| 'BDT'
    				| 'BGN'
    				| 'BHD'
    				| 'BIF'
    				| 'BMD'
    				| 'BND'
    				| 'BOB'
    				| 'BRL'
    				| 'BSD'
    				| 'BTN'
    				| 'BWP'
    				| 'BYN'
    				| 'BYR'
    				| 'BZD'
    				| 'CAD'
    				| 'CDF'
    				| 'CHF'
    				| 'CLF'
    				| 'CLP'
    				| 'CNY'
    				| 'COP'
    				| 'CRC'
    				| 'CUC'
    				| 'CUP'
    				| 'CVE'
    				| 'CZK'
    				| 'DJF'
    				| 'DKK'
    				| 'DOP'
    				| 'DZD'
    				| 'EEK'
    				| 'EGP'
    				| 'ERN'
    				| 'ETB'
    				| 'EUR'
    				| 'FJD'
    				| 'FKP'
    				| 'GBP'
    				| 'GEL'
    				| 'GHS'
    				| 'GIP'
    				| 'GMD'
    				| 'GNF'
    				| 'GTQ'
    				| 'GYD'
    				| 'HKD'
    				| 'HNL'
    				| 'HRK'
    				| 'HTG'
    				| 'HUF'
    				| 'IDR'
    				| 'ILS'
    				| 'INR'
    				| 'IQD'
    				| 'IRR'
    				| 'ISK'
    				| 'JMD'
    				| 'JOD'
    				| 'JPY'
    				| 'KES'
    				| 'KGS'
    				| 'KHR'
    				| 'KMF'
    				| 'KPW'
    				| 'KRW'
    				| 'KWD'
    				| 'KYD'
    				| 'KZT'
    				| 'LAK'
    				| 'LBP'
    				| 'LKR'
    				| 'LRD'
    				| 'LSL'
    				| 'LTL'
    				| 'LVL'
    				| 'LYD'
    				| 'MAD'
    				| 'MDL'
    				| 'MGA'
    				| 'MKD'
    				| 'MMK'
    				| 'MNT'
    				| 'MOP'
    				| 'MRO'
    				| 'MRU'
    				| 'MUR'
    				| 'MVR'
    				| 'MWK'
    				| 'MXN'
    				| 'MXV'
    				| 'MYR'
    				| 'MZN'
    				| 'NAD'
    				| 'NGN'
    				| 'NIO'
    				| 'NOK'
    				| 'NPR'
    				| 'NZD'
    				| 'OMR'
    				| 'PAB'
    				| 'PEN'
    				| 'PGK'
    				| 'PHP'
    				| 'PKR'
    				| 'PLN'
    				| 'PYG'
    				| 'QAR'
    				| 'RON'
    				| 'RSD'
    				| 'RUB'
    				| 'RWF'
    				| 'SAR'
    				| 'SBD'
    				| 'SCR'
    				| 'SDG'
    				| 'SEK'
    				| 'SGD'
    				| 'SHP'
    				| 'SKK'
    				| 'SLE'
    				| 'SLL'
    				| 'SOS'
    				| 'SRD'
    				| 'STD'
    				| 'STN'
    				| 'SVC'
    				| 'SYP'
    				| 'SZL'
    				| 'THB'
    				| 'TJS'
    				| 'TMT'
    				| 'TND'
    				| 'TOP'
    				| 'TRY'
    				| 'TTD'
    				| 'TWD'
    				| 'TZS'
    				| 'UAH'
    				| 'UGX'
    				| 'USD'
    				| 'UYU'
    				| 'UZS'
    				| 'VEF'
    				| 'VES'
    				| 'VND'
    				| 'VUV'
    				| 'WST'
    				| 'XAF'
    				| 'XCD'
    				| 'XOF'
    				| 'XPF'
    				| 'YER'
    				| 'ZAR'
    				| 'ZMW'
    				| 'ZMK'
    				| 'ZWD'
    			CurrencyRate?: number
    			SubTotal?: number
    			TotalTax?: number
    			Total?: number
    			TotalDiscount?: number
    			Title?: string
    			Summary?: string
    			BrandingThemeID?: string
    			UpdatedDateUTC?: string
    			LineAmountTypes?: 'EXCLUSIVE' | 'INCLUSIVE' | 'NOTAX'
    			StatusAttributeString?: string
    			ValidationErrors?: { Message?: string }[]
    		}[]
    	}
    ) {
    	const url = new URL(`https://api.xero.com/api.xro/2.0/Quotes`)
    	for (const [k, v] of [['summarizeErrors', summarizeErrors]]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			Accept: 'application/json',
    			'xero-tenant-id': xero_tenant_id,
    			'Idempotency-Key': Idempotency_Key,
    			'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 515 days ago