//native
/**
* Worker CustomField
* Update CustomField at the worker level
*/
export async function main(
auth: RT.Paychex,
workerId: string,
workerCustomFieldId: string,
body: Body
) {
const accessToken = await getOAuthToken(auth, 'https://api.paychex.com/auth/oauth/v2/token')
const url = new URL(
`https://api.paychex.com/workers/${workerId}/customfields/${workerCustomFieldId}`
)
const response = await fetch(url, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + accessToken
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
async function getOAuthToken(auth: RT.Paychex, tokenUrl: string): Promise<string> {
const params = new URLSearchParams({
grant_type: 'client_credentials'
})
const response = await fetch(tokenUrl, {
method: 'POST',
headers: {
Authorization: 'Basic ' + btoa(`${auth.client_id}:${auth.client_secret}`),
'Content-Type': 'application/x-www-form-urlencoded'
},
body: params.toString()
})
if (!response.ok) {
const text = await response.text()
throw new Error(`OAuth token request failed: ${response.status} ${text}`)
}
const data = await response.json()
return data.access_token
}
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/
export interface Body {
/**
* The unique identifier that is autogenerated when a custom field is created
*/
workerCustomFieldId?: string
/**
* client Custom Field Id
*/
customFieldId?: string
/**
* The type of field the custom field is
*/
type?: 'DROPDOWN' | 'TEXT' | 'BOOLEAN' | 'DATE' | 'NUMERIC, NUMERIC__0_00_ OR NUMERIC__0_0000_'
/**
* The value for BOOLEAN type (true/false)
*/
booleanValue?: boolean
/**
* The value for TEXT type (any text, alphanumeric, special characters allowed)
*/
textValue?: string
/**
* Numeric data type can have three formats namely - whole number, second decimal place and fourth decimal place, example: 12 , 12.34 or 12.3456
*/
numericValue?: number
/**
* The value for DATE type , example : 2012-02-01T05:00:00Z
*/
dateValue?: string
/**
* The unique identifier that is autogenerated when dropdown list is created
*/
dropdownId?: string
/**
* The value for dropdown list
*/
dropdownValue?: string
/**
* The name of the custom field. Such as: "Hobbies"
*/
customFieldName?: string
/**
* Where to indicate if the custom field is required on the worker where true = required and false = not required
*/
required?: boolean
/**
* Where to indicate if the custom field is required on the workers pay stub, where true = required and false = not required.
*/
checkStub?: boolean
/**
* Where to indicate if the custom field is able to be edited by the employee, where true = required and false = not required.
*/
employeeEditable?: boolean
[k: string]: unknown
}
Submitted by hugo697 235 days ago