Edits history of script submission #10134 for ' Creates a new deduction (xero)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xero = {
    	token: string
    }
    /**
     * Creates a new deduction
     *
     */
    export async function main(
    	auth: Xero,
    	Xero_Tenant_Id: string,
    	Idempotency_Key: string,
    	body: {
    		deductionId?: string
    		deductionName: string
    		deductionCategory?:
    			| 'CapitalContributions'
    			| 'ChildCareVoucher'
    			| 'MakingGood'
    			| 'PostgraduateLoanDeductions'
    			| 'PrivateUsePayments'
    			| 'SalarySacrifice'
    			| 'StakeholderPension'
    			| 'StakeholderPensionPostTax'
    			| 'StudentLoanDeductions'
    			| 'UkOther'
    		liabilityAccountId: string
    		currentRecord?: false | true
    		standardAmount?: number
    		reducesSuperLiability?: false | true
    		reducesTaxLiability?: false | true
    		calculationType?: 'FixedAmount' | 'PercentageOfGross'
    		percentage?: number
    		subjectToNIC?: false | true
    		subjectToTax?: false | true
    		isReducedByBasicRate?: false | true
    		applyToPensionCalculations?: false | true
    		isCalculatingOnQualifyingEarnings?: false | true
    		isPension?: false | true
    	}
    ) {
    	const url = new URL(`https://api.xero.com/payroll.xro/2.0/Deductions`)
    
    	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