Edits history of script submission #19842 for ' Update a timesheet (sage_intacct)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type SageIntacct = {
    	token: string
    }
    /**
     * Update a timesheet
     * Updates an existing timesheet by setting field values. Any fields not provided remain unchanged.
    
    
    Permissions and other requirements
    
    SubscriptionTime & Expenses
    User typeBusiness, Project Manager, or Employee
    PermissionsUpdate Timesheets
    
    
    
    
     */
    export async function main(
    	auth: SageIntacct,
    	key: string,
    	body: {
    		key?: string
    		id?: string
    		href?: string
    		beginDate?: string
    		endDate?: string
    		postingDate?: string
    		state?:
    			| 'submitted'
    			| 'approved'
    			| 'partiallyApproved'
    			| 'declined'
    			| 'draft'
    			| 'partiallyDeclined'
    			| 'saved'
    		unitOfMeasure?: string
    		hoursInDay?: number
    		description?: string
    		calculationMethod?: 'hourly' | 'salary'
    		postActualLaborCost?: false | true
    		employee?: { key?: string; id?: string; href?: string }
    		employeeContact?: {
    			key?: string
    			id?: string
    			firstName?: string
    			lastName?: string
    			href?: string
    		}
    		attachment?: { key?: string; id?: string; href?: string }
    		lines?: {
    			key?: string
    			id?: string
    			href?: string
    			timesheet?: { key?: string; id?: string; href?: string }
    			entryDate?: string
    			quantity?: number
    			lineNumber?: number
    			description?: string
    			notes?: string
    			state?:
    				| 'submitted'
    				| 'approved'
    				| 'partiallyApproved'
    				| 'declined'
    				| 'draft'
    				| 'saved'
    				| 'readyForApproval'
    			timeType?: { key?: string; id?: string; href?: string }
    			isBillable?: false | true
    			isBilled?: 'true' | 'false' | 'partial'
    			statisticalJournal?: { key?: string; id?: string; href?: string }
    			billableUtilizedGLAccount?: { key?: string; id?: string; href?: string }
    			nonBillableUtilizedGLAccount?: {
    				key?: string
    				id?: string
    				href?: string
    			}
    			billableNonUtilizedGLAccount?: {
    				key?: string
    				id?: string
    				href?: string
    			}
    			nonBillableNonUtilizedGLAccount?: {
    				key?: string
    				id?: string
    				href?: string
    			}
    			hours?: {
    				billable?: number
    				nonBillable?: number
    				approved?: number
    				approvedBillable?: number
    				approvedNonBillable?: number
    				utilized?: number
    				nonUtilized?: number
    				approvedUtilized?: number
    				approvedNonUtilized?: number
    			}
    			externalPayroll?: {
    				costRate?: number
    				billingRate?: number
    				amount?: string
    				employerTaxes?: number
    				fringes?: number
    				cashFringes?: number
    			}
    			laborClass?: { key?: string; id?: string; name?: string; href?: string }
    			laborShift?: { key?: string; id?: string; name?: string; href?: string }
    			laborUnion?: { key?: string; id?: string; name?: string; href?: string }
    			dimensions?: {
    				location?: { key?: string; id?: string; name?: string; href?: string }
    				department?: {
    					key?: string
    					id?: string
    					name?: string
    					href?: string
    				}
    				employee?: { key?: string; id?: string; name?: string; href?: string }
    				project?: { key?: string; id?: string; name?: string; href?: string }
    				customer?: { key?: string; id?: string; name?: string; href?: string }
    				vendor?: { key?: string; id?: string; name?: string; href?: string }
    				item?: { key?: string; id?: string; name?: string; href?: string }
    				warehouse?: { key?: string; id?: string; name?: string; href?: string }
    				class?: { key?: string; id?: string; name?: string; href?: string }
    				task?: { id?: string; key?: string; name?: string; href?: string }
    				costType?: { id?: string; key?: string; name?: string; href?: string }
    				asset?: { id?: string; key?: string; name?: string; href?: string }
    				contract?: { id?: string; key?: string; name?: string; href?: string }
    				affiliateEntity?: {
    					key?: string
    					id?: string
    					href?: string
    					name?: string
    				}
    			} & {
    				location?: { key?: string; id?: string; name?: string; href?: string }
    				department?: {
    					key?: string
    					id?: string
    					name?: string
    					href?: string
    				}
    			}
    			audit?: {
    				createdDateTime?: string
    				modifiedDateTime?: string
    				createdBy?: string
    				modifiedBy?: string
    			}
    		}[]
    		audit?: {
    			createdDateTime?: string
    			modifiedDateTime?: string
    			createdBy?: string
    			modifiedBy?: string
    		}
    		entity?: { key?: string; id?: string; name?: string; href?: string }
    	} & { id?: {} }
    ) {
    	const url = new URL(`https://api.intacct.com/ia/api/v1/objects/time/timesheet/${key}`)
    
    	const response = await fetch(url, {
    		method: 'PATCH',
    		headers: {
    			'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 235 days ago