Edits history of script submission #10171 for ' Creates employment detail for a specific employee using a unique employee ID (xero)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xero = {
    	token: string
    }
    /**
     * Creates employment detail for a specific employee using a unique employee ID
     *
     */
    export async function main(
    	auth: Xero,
    	EmployeeID: string,
    	Xero_Tenant_Id: string,
    	Idempotency_Key: string,
    	body: {
    		payrollCalendarID: string
    		startDate: string
    		employeeNumber: string
    		niCategory: 'A' | 'B' | 'C' | 'F' | 'H' | 'I' | 'J' | 'L' | 'M' | 'S' | 'V' | 'X' | 'Z'
    	}
    ) {
    	const url = new URL(`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/Employment`)
    
    	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