//native
/**
* Worker Contacts
* Update a worker contact.
*/
export async function main(auth: RT.Paychex, workerId: string, contactId: 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}/contacts/${contactId}`)
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 ID for the workers specific contact.
*/
contactId?: string
/**
* The type of this worker contact. Required for POST contacts.
*/
contactType?: {
/**
* The ID for specific type of contact. Required for POST contacts.
*/
contactTypeId?: string
/**
* Enum: "EMERGENCY_CONTACT"
*
* The name for specific type of contact.
*/
contactTypeName?: string
[k: string]: unknown
}
/**
* The relationship for this worker contract. Required for POST contacts.
*/
relationship?: {
/**
* The ID for the workers relationship to contact.
*/
relationshipId?: string
/**
* The ID for the workers specific relation.
*/
relationWeid?: string
/**
* The relationship type for this worker contact. Required for POST person contacts.
*/
relationshipType?: {
/**
* ID of worker specific type of relationship with the contact. Required for POST contacts.
*/
relationshipTypeId?: string
/**
* The name of worker specific type of relationship with the contact.
*
* Enum: "Spouse", "Parent", "Sibling", "Child", "Friend", "Domestic Partner", "Other"
*/
relationshipTypeName?: string
[k: string]: unknown
}
/**
* Where to indicate if the contact is selected as Primary, where true = Primary contact and false = not Primary contact.
*/
primary?: boolean
/**
* The person associated with this relationship. The relationship must have either a person or entity.
*/
person?: {
/**
* 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 set of communications for this contact. Required for POST contacts.
*/
communication?: {
/**
* The telecom communications for this contact.
*/
telecom?: {
/**
* The ID for the workers relationship to contact.
*/
communicationId?: string
/**
* The country code. Required for POST contacts.
*/
dialCountry?: string
/**
* The area code. Required for POST contacts.
*/
dialArea?: string
/**
* The phone number. Required for POST contacts.
*/
dialNumber?: string
/**
* Enum: "PHONE", "MOBILE_PHONE"
*
* Indicates whether or not the number is for a mobile device. Required for POST contacts.
*/
type?: string
/**
* Enum: "PERSONAL", "BUSINESS"
*
* A code classifying a designated use associated with a contact method. For example, whether a telephone or email address is one for work communications or one primarily for personal use. This data field cannot be PATCHED. Required for POST contacts.
*/
usageType?: string
/**
* The phone extension.
*/
extension?: string
[k: string]: unknown
}[]
/**
* The postal communications for this contact.
*/
postal?: {
/**
* The ID for the workers relationship to contact.
*/
communicationId?: string
/**
* The street address line one. Required for street address. Required for POST contacts.
*/
streetLineOne?: string
/**
* The street address line two.
*/
streetLineTwo?: string
/**
* The postal office box. Required for PO Box with POST contacts.
*/
postOfficeBox?: string
/**
* The city name. Required for POST contacts.
*/
city?: string
/**
* The zip-code. Required for POST contacts.
*/
postalCode?: string
/**
* The state code (ISO 3166 subdivision code). Required for POST contacts.
*/
countrySubdivisionCode?: string
/**
* The country code (ISO 3166 alpha-2). Required for POST contacts.
*/
countryCode?: string
[k: string]: unknown
}[]
/**
* The email communications for this contact.
*/
email?: {
/**
* The ID for this email communication.
*/
communicationId?: string
/**
* The mailto address as specified in RFC2368. Required for POST contacts.
*/
uri?: string
/**
* Enum: "PERSONAL", "BUSINESS"
*
* A code classifying a designated use associated with a contact method. For example, whether a telephone or email address is one for work communications or one primarily for personal use. This data field cannot be PATCHED. Required for POST contacts.
*/
usageType?: string
[k: string]: unknown
}[]
[k: string]: unknown
}
[k: string]: unknown
}
/**
* The organization associated with this relationship. The relationship must have either a person or entity.
*/
entity?: {
/**
* The ID for this contact.
*/
entityId?: string
/**
* The entity name. Required for POST contacts.
*/
entityName?: string
/**
* The set of communications for this contact. Required for POST contacts.
*/
communication?: {
/**
* The telecom communications for this contact.
*/
telecom?: {
/**
* The ID for the workers relationship to contact.
*/
communicationId?: string
/**
* The country code. Required for POST contacts.
*/
dialCountry?: string
/**
* The area code. Required for POST contacts.
*/
dialArea?: string
/**
* The phone number. Required for POST contacts.
*/
dialNumber?: string
/**
* Enum: "PHONE", "MOBILE_PHONE"
*
* Indicates whether or not the number is for a mobile device. Required for POST contacts.
*/
type?: string
/**
* Enum: "PERSONAL", "BUSINESS"
*
* A code classifying a designated use associated with a contact method. For example, whether a telephone or email address is one for work communications or one primarily for personal use. This data field cannot be PATCHED. Required for POST contacts.
*/
usageType?: string
/**
* The phone extension.
*/
extension?: string
[k: string]: unknown
}
/**
* The postal communications for this contact.
*/
postal?: {
/**
* The ID for the workers relationship to contact.
*/
communicationId?: string
/**
* The street address line one. Required for street address. Required for POST contacts.
*/
streetLineOne?: string
/**
* The street address line two.
*/
streetLineTwo?: string
/**
* The postal office box. Required for PO Box with POST contacts.
*/
postOfficeBox?: string
/**
* The city name. Required for POST contacts.
*/
city?: string
/**
* The zip-code. Required for POST contacts.
*/
postalCode?: string
/**
* The state code (ISO 3166 subdivision code). Required for POST contacts.
*/
countrySubdivisionCode?: string
/**
* The country code (ISO 3166 alpha-2). Required for POST contacts.
*/
countryCode?: string
[k: string]: unknown
}
/**
* The email communications for this contact.
*/
email?: {
/**
* The ID for this email communication.
*/
communicationId?: string
/**
* The mailto address as specified in RFC2368. Required for POST contacts.
*/
uri?: string
/**
* Enum: "PERSONAL", "BUSINESS"
*
* A code classifying a designated use associated with a contact method. For example, whether a telephone or email address is one for work communications or one primarily for personal use. This data field cannot be PATCHED. Required for POST contacts.
*/
usageType?: string
[k: string]: unknown
}
[k: string]: unknown
}
[k: string]: unknown
}
[k: string]: unknown
}
[k: string]: unknown
}
Submitted by hugo697 235 days ago