Edits history of script submission #10464 for ' Updates a specific employee's detail (xero)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xero = {
    	token: string
    }
    /**
     * Updates a specific employee's detail
     *
     */
    export async function main(
    	auth: Xero,
    	EmployeeID: string,
    	Xero_Tenant_Id: string,
    	Idempotency_Key: string,
    	body: {
    		employeeID?: string
    		title: string
    		firstName: string
    		lastName: string
    		dateOfBirth: string
    		address: {
    			addressLine1: string
    			addressLine2?: string
    			city: string
    			postCode: string
    			countryName?: string
    		}
    		email?: string
    		gender: 'M' | 'F'
    		phoneNumber?: string
    		startDate?: string
    		endDate?: string
    		payrollCalendarID?: string
    		updatedDateUTC?: string
    		createdDateUTC?: string
    		nationalInsuranceNumber?: string
    		isOffPayrollWorker?: false | true
    	}
    ) {
    	const url = new URL(`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}`)
    
    	const response = await fetch(url, {
    		method: 'PUT',
    		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