//native
/**
* Worker
* Update a unique worker (employee and contractor) that your application has been granted access to modify.
*/
export async function main(auth: RT.Paychex, workerId: 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}`)
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 associated with this worker representation.
*/
workerId?: string
/**
* The workers employee identification information.
*/
employeeId?: string
/**
* The type of worker. This data field cannot be PATCHED.NOTE: An IN_PROGRESS worker cannot be POSTED with a value of CONTRACTOR.
*/
workerType?: 'EMPLOYEE' | 'CONTRACTOR' | 'INDEPENDENT_CONTRACTOR'
/**
* The type of employment for the worker.
*/
employmentType?: 'FULL_TIME' | 'PART_TIME'
/**
* The workers custom employment type
*/
customEmploymentType?: {
/**
* Unique ID for the custom employment type which the worker is assigned to. This data field cannot be PATCHED for IN_PROGRESS workers.
*/
customEmploymentTypeId?: string
/**
* The name of the custom employment type that the worker is assigned to.
*/
customEmploymentTypeName?: string
[k: string]: unknown
}
/**
* The Overtime classification of the worker. This data field cannot be PATCHED for ACTIVE workers.
*/
exemptionType?: 'EXEMPT' | 'NON_EXEMPT'
/**
* The state(s) in which the worker works in.
*/
workState?: string
/**
* The workers date of birth. It cannot be greater than today's date.
*/
birthDate?: string
sex?: 'MALE' | 'FEMALE' | 'NOT_SPECIFIED'
/**
* Disclaimer:This parameter is not visible in Flex for the client. This data field cannot be PATCHED for ACTIVE workers.
*/
ethnicityCode?: string
/**
* The date which the worker was hired. It cannot be PATCHED for ACTIVE workers.
*/
hireDate?: string
/**
* The clock ID of the worker that can be an identification for other systems.
*/
clockId?: string
/**
* Information about the workers name.
*/
name?: {
/**
* The family or last name of a worker.
*/
familyName?: string
/**
* A subordinate given name, or initial representing that name, of a worker. <br />NOTE: Please send in just a single character initial for middleName. <br />If sending in more than one character the name will be truncated the first letter of the middleName. <br /> A full middle name can be entered directly in Paychex Flex only at this time.
*/
middleName?: string
/**
* The given or first name of a worker. For an independent contractor that is a company rather than an individual, the name of the company.
*/
givenName?: string
/**
* The first name that the worker prefers to go by
*/
preferredName?: string
/**
* The last name that the worker prefers to go by
*/
preferredLastName?: string
/**
* The pronoun that the worker prefers to go by. This data field cannot be POSTED.
*/
pronoun?: string
/**
* A qualifier to the name of a worker, indicating generation.
*/
qualificationAffixCode?: string
/**
* A personal title that comes before an individual's name in a formal address (such as Dr., Prof., Rev., Mr.).
*/
titleAffixCode?: string
[k: string]: unknown
}
/**
* The workers seniority date. This data field cannot be POSTED or PATCHED.
*/
seniorityDate?: string
/**
* The workers profile image url. This data field cannot be POSTED or PATCHED.
*/
profileImageURL?: string
/**
* The workers legal tax identification information. This data field cannot be PATCHED for ACTIVE workers.
*/
legalId?: {
/**
* A value that identifies the type of taxpayer identification number provided. SSN: Social Security Number - 9 digit number , FEIN: Federal Employer Identification Number (EIN)
*/
legalIdType?: 'SSN' | 'FEIN'
/**
* The federal level taxpayer id number that the worker has provided
*/
legalIdValue?: string
[k: string]: unknown
}
/**
* The workers home labor assignment.
*/
laborAssignmentId?: string
/**
* The workers location.
*/
locationId?: string
/**
* The workers home job
*/
jobId?: string
/**
* The workers current job/position information.
*/
job?: {
/**
* Unique ID for that job within the company that the worker is assigned to.
*/
jobTitleId?: string
/**
* The name of the title that the worker is assigned to.
*/
title?: string
[k: string]: unknown
}
/**
* The organization which the worker is part of.
*/
organization?: {
/**
* The unique identifier associated with this organizations representation.
*/
organizationId?: string
/**
* The name of the organization.
*/
name?: string
/**
* The number assigned to the organization.
*/
number?: string
/**
* The level number within the organizational structures hierarchy.
*/
level?: string
links?: {
rel?: string
href?: string
hreflang?: string
media?: string
title?: string
type?: string
deprecation?: string
profile?: string
name?: string
[k: string]: unknown
}[]
[k: string]: unknown
}
/**
* The workers supervisor information. Supervisor cannot be a TERMINATED or IN_PROGRESS worker.
*/
supervisor?: {
/**
* The supervisor's Id
*/
workerId?: string
/**
* Information about the workers name.
*/
name?: {
/**
* The family or last name of a worker.
*/
familyName?: string
/**
* A subordinate given name, or initial representing that name, of a worker. <br />NOTE: Please send in just a single character initial for middleName. <br />If sending in more than one character the name will be truncated the first letter of the middleName. <br /> A full middle name can be entered directly in Paychex Flex only at this time.
*/
middleName?: string
/**
* The given or first name of a worker. For an independent contractor that is a company rather than an individual, the name of the company.
*/
givenName?: string
/**
* The first name that the worker prefers to go by
*/
preferredName?: string
/**
* The last name that the worker prefers to go by
*/
preferredLastName?: string
/**
* The pronoun that the worker prefers to go by. This data field cannot be POSTED.
*/
pronoun?: string
/**
* A qualifier to the name of a worker, indicating generation.
*/
qualificationAffixCode?: string
/**
* A personal title that comes before an individual's name in a formal address (such as Dr., Prof., Rev., Mr.).
*/
titleAffixCode?: string
[k: string]: unknown
}
[k: string]: unknown
}
/**
* The workers employment status information. This data field cannot be POSTED or PATCHED for an IN_PROGRESS worker.
*/
currentStatus?: {
/**
* The unique identifier associated with this status representation.
*/
workerStatusId?: string
/**
* The workers current status.
*/
statusType?: 'ACTIVE' | 'INACTIVE' | 'TERMINATED' | 'PENDING' | 'IN_PROGRESS'
/**
* The detailed reason of the workers current status.
*/
statusReason?: string
/**
* Date that this status has started for the worker.
*/
effectiveDate?: string
order?: number
links?: {
rel?: string
href?: string
hreflang?: string
media?: string
title?: string
type?: string
deprecation?: string
profile?: string
name?: string
[k: string]: unknown
}[]
[k: string]: unknown
}
/**
* Worker Communications. This data field cannot be updated for worker endpoint.
*/
communications?: {
/**
* The ID for the workers specific communication item.
*/
communicationId?: string
/**
* A set of communication types classifying an instruction that the customer, requester, or subject must comply with in order for the screening to go forward. NOTE: PHONE and EMAIL type supports BUSINESS and PERSONAL usage type only.MOBILE_PHONE, FAX and PAGER supports BUSINESS usage type only.This data field cannot be PATCHED.
*/
type?:
| 'STREET_ADDRESS'
| 'PO_BOX_ADDRESS'
| 'PHONE'
| 'MOBILE_PHONE'
| 'FAX'
| 'EMAIL'
| 'PAGER'
/**
* A code classifying a designated use associated with a contact method. For example, whether a telephone or email address is one for business communications or one primarily for personal use.This data field cannot be PATCHED.
*/
usageType?:
| 'PERSONAL'
| 'BUSINESS'
| 'HOME'
| 'WORK'
| 'LOCATION_STREET_ADDRESS'
| 'MAILING_ADDRESS'
/**
* The country dialing code for a communication number
*/
dialCountry?: string
/**
* The area dialing code for a communication number
*/
dialArea?: string
/**
* The communication number, not including country dialing or area dialing codes
*/
dialNumber?: string
/**
* The extension of the associated communication number
*/
dialExtension?: string
/**
* The mailto address as specified in RFC2368
*/
uri?: string
/**
* The street address line one
*/
streetLineOne?: string
/**
* The street address line two
*/
streetLineTwo?: string
/**
* The postal office box. This data field cannot be PATCHED
*/
postOfficeBox?: string
/**
* The city name
*/
city?: string
/**
* The zip-code
*/
postalCode?: string
/**
* The zip-code extension
*/
postalCodeExtension?: string
/**
* The state code (ISO 3166 subdivision code)
*/
countrySubdivisionCode?: string
/**
* The country code (ISO 3166 alpha-2)
*/
countryCode?: string
links?: {
rel?: string
href?: string
hreflang?: string
media?: string
title?: string
type?: string
deprecation?: string
profile?: string
name?: string
[k: string]: unknown
}[]
[k: string]: unknown
}[]
links?: {
rel?: string
href?: string
hreflang?: string
media?: string
title?: string
type?: string
deprecation?: string
profile?: string
name?: string
[k: string]: unknown
}[]
/**
* Id that you define which is used for error handling/responses.This data field is used while POSTING multiple IN_PROGRESS workers
*/
workerCorrelationId?: string
[k: string]: unknown
}
Submitted by hugo697 235 days ago